简体   繁体   中英

Ruby Rails Mongrel Server ODBC connection reset

I am currently running ruby on rails (ruby 1.8.7, rails 2.3.8) on a windows 2008 server in IIS7. I am using mongrel rails to run the instances and then adding the instances to a server farm in IIS7 to be used.

When the application is running and somehow the connection to the database server goes down, it seems that the rails app is still trying to connect using the ODBC connection and I get the following error

ActiveRecord::StatementInvalid (ODBC::Error: S0002 (208) [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'sessions_table'.: SELECT TOP 1 * FROM [sessions_table] WHERE ([sessions_table].[session_id] = 'e6a7e7bc3b72edf2662c2b97793694d2') ):
  vendor/gems/activerecord-sqlserver-adapter-2.3.10/lib/active_record/connection_adapters/sqlserver_adapter.rb:946:in `raw_select'
  vendor/gems/activerecord-sqlserver-adapter-2.3.10/lib/active_record/connection_adapters/sqlserver_adapter.rb:923:in `select'
  app/controllers/application_controller.rb:107:in `set_locale'
  haml (3.0.17) [v] lib/sass/plugin/rack.rb:41:in `call'
  haml (3.0.17) [v] lib/sass/plugin/rack.rb:41:in `call'
  config/initializers/mongrel.rb:62:in `dispatch_cgi'

This error goes away when i restart the mongrel services, however, I would really like it if the application recognized the odbc error and reset the connection automatically. Any ideas?

If you are sure that your table name is correct, then check the way you defined it in your model. Definition should contain database name and schema name (usually 'dbo').

For Rails 2.xx it will be:

set_table_name "database_name.dbo.table_name"

And for Rails >= 3.xx:

self.table_name = "database_name.dbo.table_name"

Can you trap this exception and try reconnect! ?

Once the reset happens (RST?), its likely that the adapters impelementation now has an invalid connection, or connection pool. I am wondering if reconnect! would reset connection/connection pool and allow the client to gracefully continue. Or at least try [n] more times before giving up.

HTH,

Z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM