I was having this error all the time. Not on my own dev machine, but as
soon as we deployed it, after a few requests, this error came up.
Jeremy helped me a bit to get it solved, and I would like to share it.
The problem really came from my lack of understanding of the Ruby on Rails
stack, combined with the fact that we want to access multiple (two)
databases.
>From the Sequel documentation, you can find which instructions to use, but
they don't tell you where exactly to put these instructions.
What we ended up with:
In *config/application.rb* configure plugins to load:
config.sequel.after_connect = proc do
Sequel::Model.plugin :mssql_optimistic_locking, lock_column:
:TimeStamp
Sequel::Model.plugin :kendo
end
In *config/initializers/sequel.rb*
Sequel::Database.identifier_output_method = nil #to maintain the casing
of field names from our MSSQL db
Sequel::Database.identifier_input_method = nil
DB = Sequel.connect(YAML.load(File.read('config/database.yml'))[Rails.env])
PLANNING =
Sequel.connect(YAML.load(File.read('config/database.yml'))["planning-#{Rails.env}"])
PLANNING.cache_schema = true #good for performance
# For FactoryGirl support:
class Sequel::Model
def save!
save(:validate=>false)
end
end
Our models look like this:
class Order < Sequel::Model(PLANNING[:Orders])
The mistake I made, was that I open the connection in the initializer, i.e.
when the application starts, and that every request uses this single
connection.
What I needed to do, was close the connection at the beginning of every
request, so the Sequel connection pool manager can open additional
connections when needed.
To make sure the connection is closed after the app is initialized, I added
to *config.ru*
PLANNING.disconnect
DB.disconnect
To make sure a fresh connection is opened, I added these same instructions
to *app/controllers/application_controller.rb* in a *before_action* method.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.