I have the following setup:
# config/my_second_database.yml
default: &default
adapter: 'sqlserver'
username: <%= ENV['MSSQL_USER'] %>
password: <%= ENV['MSSQL_PASSWORD'] %>
dataserver: <%= ENV['MSSQL_HOST'] %>
database: <%= ENV['MSSQL_DB'] %>
pool: 5
# app/models/base_record.rb
class BaseRecord < ActiveRecord::Base
self.abstract_class = true
self.ignored_columns = %w(class)
establish_connection MY_SECOND_DB
end
# app/models/my_model.rb
class MyModel < BaseRecord
end
While inside the rails console:
MyModel.first
#=> #<MyModel:0x00>
# Leave idle for a few minutes
MyModel.first
#=> ActiveRecord::StatementInvalid: TinyTds::Error: DBPROCESS is dead or not enabled ... gems/activerecord-sqlserver-adapter-5.0.7/lib/active_record/connection_adapters/sqlserver/database_statements.rb:354:in `cancel'
MyModel.connection.active?
#=> false
MyModel.connection.reconnect!
MyModel.connection.active?
#=> true
MyModel.first
#=> #<MyModel:0x00>
Leaving the connection idle bubbles the error ActiveRecord::StatementInvalid: TinyTds::Error: DBPROCESS is dead or not enabled.
Gems:
rails (5.05)
activerecord-sqlserver-adapter (5.0.7)
tiny_tds (0.7.0)
Is there a way to reconnect automatically or prevent the error from being raised?
I have the following setup:
While inside the rails console:
Leaving the connection idle bubbles the error
ActiveRecord::StatementInvalid: TinyTds::Error: DBPROCESS is dead or not enabled.Gems:
rails (5.05)
activerecord-sqlserver-adapter (5.0.7)
tiny_tds (0.7.0)
Is there a way to reconnect automatically or prevent the error from being raised?