Indications that we are leaking connections

http://blogs.msdn.com/b/bindeshv/archive/2008/03/02/indications-that-we-are-leaking-connections.aspx

We get a lot of queries from developers around the following error while they are using ADO.NET

"Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."

Most of the times this is an indication that we are leaking connection. Yes, but you would state that how can this be possible since we are explicitly closing the connection in the code. I do agree, but what happens if the program follows a different code path. Here is a link where the issue is explained in depth

http://blogs.msdn.com/angelsb/archive/2004/08/25/220333.aspx

By default, the max pool size is set to 100. This is more than sufficient unless your program opens 101 connections inside a single thread, which is a rare scenario.

Most of the times you are lucky since the GC will try to recover the unused SqlConnection object, and so you might not get this error at all. And so if you right a sample application to test the error, that opens 101 connections and does not close it , you will not see the error, since chances are that GC would have reclaimed the open connection.

How do we identify if we have a connection leak ?

Simplest way to identify a connection leak is to run the Performance Monitor utility and add the .Net Data Provider for SQL Server for the given process that you suspect leaks the connection. Please remember that you need to attach it to the right application process else you will not have correct information.

Once attached look for the NumberOfReclaimedConnections. This counter is a newly added counter for ADO.NET 2.0 . Any number here will tell the story.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值