0

我有一个 ruby​​ 应用程序,它连接到 SQL 服务器(工作正常)和 Postgres(中断)。我不知道如何调试这个。我尝试从命令行连接到 postgres 数据库并且它工作(实际上没有密码)。

ActiveRecord::ConnectionNotEstablished它在第一行引发错误:

nti_shipment.line_items.each_with_index do |nti_line_item,i|
  #logger.info "\n\nadd line item to shipto: "+nti_line_item.botcode+"****"

  product = Web::Product.find_by_nti_product_id(nti_line_item.botcode)

  #is_message = (i > 0 && (not product)) ? true : false

  is_message = (nti_line_item.productid == 0) ? true : false

  if !(is_message) 
    web_line_item = web_shipment.add_line_item(nti_line_item)
    last_item = web_line_item
    nti_line_item.itemid = web_line_item.id
    nti_line_item.save!
  elsif i > 0  
    last_item.line_item_messages << Web::LineItemMessage.add(last_item,nti_line_item)
  end
end

这是我正在使用的 database.yml 文件:

production: 
  adapter: postgresql
  database: mysite_production
  username: myuser
  password: "password"
  options: "-o sslmode=require"
  host: localhost

这是完整的跟踪:

    I, [2013-10-03T10:24:45.034384 #16480]  INFO -- : ActiveRecord::ConnectionNotEstablished
    I, [2013-10-03T10:24:45.105416 #16480]  INFO -- : /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/arel/visitors/sqlserver.rb:81:in `engine_activerecord_sqlserver_adapter?'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/arel/visitors/sqlserver.rb:33:in `order'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation/query_methods.rb:279:in `build_arel'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation/query_methods.rb:260:in `arel'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation.rb:171:in `exec_queries'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation.rb:160:in `block in to_a'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/explain.rb:41:in `logging_query_plan'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation.rb:159:in `to_a'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation/finder_methods.rb:159:in `all'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:382:in `find_target'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:335:in `load_target'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:219:in `block (4 levels) in create_web_orders'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:89:in `each'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:194:in `block (3 levels) in create_web_orders'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:52:in `block in transaction'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/core_ext/database_statements.rb:37:in `transaction_with_retry_deadlock_victim'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:52:in `transaction'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:167:in `block (2 levels) in create_web_orders'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:166:in `block in create_web_orders'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:164:in `each'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:164:in `create_web_orders'
    /usr/local/sl-exchange/app/controllers/order_controller.rb:28:in `start'
    /usr/local/sl-exchange/lib/exchange.rb:115:in `initialize'
    /usr/local/sl-exchange/lib/exchange.rb:194:in `new'
    /usr/local/sl-exchange/lib/exchange.rb:194:in `<top (required)>'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:203:in `load'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:203:in `start_load'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:298:in `start'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/controller.rb:70:in `run'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons.rb:147:in `block in run'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `call'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `catch_exceptions'
    /usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons.rb:146:in `run'

这是我的宝石:

** LOCAL GEMS ***

activemodel (3.2.14)
activerecord (3.2.14)
activerecord-postgresql-adapter (0.0.1)
activerecord-sqlserver-adapter (3.2.12)
activesupport (3.2.14)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
daemons (1.1.9)
i18n (0.6.5)
io-console (0.3)
json (1.5.5)
mailfactory (1.4.0)
mime-types (1.24)
mini_portile (0.5.1)
minitest (2.5.1)
multi_json (1.7.9)
nokogiri (1.6.0)
pg (0.15.1)
rake (10.1.0, 0.9.2.2)
rchardet (1.3.1)
rdoc (3.9.5)
RedCloth (4.2.9)
rubygems-bundler (1.2.2)
rvm (1.11.3.8)
sanitize (2.0.6)
tiny_tds (0.6.1)
tzinfo (0.3.37)

如果您需要更多信息,请告诉我。

===== SQLSERVER 配置 =====

production:
  adapter: sqlserver
  host: cluster.mysite.com
  database: mydb
  #dsn: preview
  username: myuser
  password: mypwd
  port: 1433

当我尝试telnet cluster.mysite.com 1433它的工作...所以我不知道发生了什么。

4

1 回答 1

1

您在 database.yml 中的配置显示为 postgresql,但是,您的错误跟踪中包含 activerecord-sqlserver-adapter-3.2.12。所以,看起来,你仍然在尝试连接到 sqlserver。所以,这不是 postgres 中断,而是 sqlserver 中断。

于 2013-10-03T15:47:13.933 回答