企业库5.0强行关闭活动连接
如何强制关闭数据库连接?
我用来创建连接的示例代码是:
class Customer{
private readonly Database _db;
public Customer(){
_db = = DatabaseFactory.CreateDatabase(_userSettings.ConnstringName);
}
.. stuff to use this connection..
}
How can I close Database connection forcefully?
The sample code I'm using to create connection is:
class Customer{
private readonly Database _db;
public Customer(){
_db = = DatabaseFactory.CreateDatabase(_userSettings.ConnstringName);
}
.. stuff to use this connection..
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代码(.. 使用此连接的内容..)放入
using
块中,这将确保连接关闭。例如:和:
使用块是确保资源正确关闭的好方法:
否则,您必须在连接对象上显式调用
Close()
方法:Put the code (.. stuff to use this connection..) inside a
using
block, which will ensure the connection is closed. For example:and:
Using blocks are a nice way of ensuring resources are closed properly:
Otherwise, you have to explicitly call the
Close()
method on the connection object: