Jack Marchetti
Jack Marchetti

Reputation: 15754

Properly close a SQL connection in Ruby on Rails?

I have a pretty complex SQL query which can't be done, or can't be done easily, in ActiveRecord.

I created my SQL query and did this:

sql = getcomplexsqlquery
result = ActiveRecord::Base.connection.execute(sql)

and loop through the result.

How do I make sure that the SQL connection gets closed?

Upvotes: 3

Views: 2272

Answers (1)

the Tin Man
the Tin Man

Reputation: 160601

Don't try to close it.

You are using ActiveRecord's connection to your database, which is the same one it would use for its normal queries.

Closing one would close the other, leaving one angry ActiveRecord and Rails as a result.

Upvotes: 7

Related Questions