如何强制SQLconnection释放数据库?
我编写了一个小应用程序,可以恢复数据库(C# 和 SQL2005),但是在访问数据库后,我无法删除它 - 它说它正在使用中。 我想这与 SQLconnection-pooling 有关,但是我可以强制它释放数据库吗?
I have written a small application, that can restore a database (C# and SQL2005), but after I have accessed the database, I can't drop it - it says that it is in use..
I guess it has to do with the SQLconnection-pooling, but can I force it to relase the database??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在连接字符串中指定“Pooling=False”。
Specify 'Pooling=False' in the connection string.
处置您的 SqlConnection 对象。
Dispose your SqlConnection object.
如果您使用
我认为这会在退出后强制释放资源
If you utlise
I think this then forces the freeing of resources after it exits
之一
调用“USE SomeOtherDB”(例如Master)来关闭自己的连接,或者调用ALTER DATABASE SET SINGLE_USER
或
ALTER DATABASE SET SINGLE_USER WITH ROLLBACK_IMMEDIATE
来关闭其他连接。 第一个等待连接结束,第二个是立即连接。
Call "USE SomeOtherDB" (e.g Master) to close your own connection, or one of
ALTER DATABASE SET SINGLE_USER
or
ALTER DATABASE SET SINGLE_USER WITH ROLLBACK_IMMEDIATE
to close other connections. The first waits for connections to conclude, the second is immediate.
“调用“USE SomeOtherDB”(例如Master)来关闭您自己的连接,或其中之一”
"Call "USE SomeOtherDB" (e.g Master) to close your own connection, or one of"