.net mysql 手动清理连接池_.net sqlserver 关于连接池没事释放的注意项

CAUTIONIt is recommended that you always close the Connection when you are finished using it in order for the connection to be returned to the pool. This can be done using either the Close or Dispose methods of the Connection object. Connections that are not explicitly closed might not be added or returned to the pool. For example, a connection that has gone out of scope but that has not been explicitly closed will only be returned to the connection pool if the maximum pool size has been reached and the connection is still valid.

Note   Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class. In a finalizer, only release unmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a Finalize method in your class definition. For more information, see Programming for Garbage Collection.

注意:在使用完成之后建议使用Close或Dispose关闭数据链接,确保链接可以返回链接池中。链接没有立即关闭可能是因为没有添加或返回到链接池中。例如:当一个链接在执行域结束后没有被关闭,那么它将在链接数达到最大值或链接无效时才返回数据库链接池中。

Note:不要在Finalize method(析构函数)中使用Close或者Dispose来释放Connection,DataReader或其他托管对象。在析构函数中,仅释放在对象中直接使用的非托管资源。如果你的对象中没有使用非托管资源,不要定义析构函数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值