Reputation: 15754
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
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