如何从Rails中的特定数据库断开连接? [英] How to disconnect from a particular database in rails?
本文介绍了如何从Rails中的特定数据库断开连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码段连接到另一个数据库
I use this snippet to connect to another db
ActiveRecord::Base.establish_connection....
但我不知道在不需要此连接后如何删除它。
but I don't know how to delete this connection after it is not needed.
推荐答案
您可以调用删除连接
old_connection = ActiveRecord::Base.remove_connection
如果您已完成操作像下面的(有分配)
If you have done something like the following (where there is an assignment)
new_connection = ActiveRecord::Base.establish_connection(...)
这可以传递给 remove_connection
old_connection = ActiveRecord::Base.remove_connection(new_connection)
您可以在源代码。
这篇关于如何从Rails中的特定数据库断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文