0

I have a ruby app and it makes a connection to SQL server (works fine) and Postgres (breaking). I don't know how to debug this. I tried connecting to the postgres database from the command line and it worked (without a password actually).

It throws a ActiveRecord::ConnectionNotEstablished error on the first line:

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

And this is the database.yml file I'm using:

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

This is the full trace:

    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'

Here are my gems:

** 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)

Let me know if you need more info.

===== SQLSERVER CONFIG =====

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

when I try telnet cluster.mysite.com 1433 it works... so I don't know what's going on.

1 Answer 1

1

Your configuration in database.yml says postgresql, but, your error trace has activerecord-sqlserver-adapter-3.2.12 in it. So, looks like, still you are trying to connect to sqlserver.So, it is not postgres breaking, it is sqlserver breaking.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I'll look into it. Do you think my sqlserver config is incorrect? How would I be able to debug my sqlserver connection?
could you please post your database yml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.