Connection Pool 与 Connect Timeout=0

最近在做多线程处理数据库的程序时,这个程序总是会报如下错误:

超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。

System.Data

   在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

   在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

   在 System.Data.SqlClient.SqlConnection.Open()

仔细用 SQL Server Management Studio 中的 Activity Monitor 查看数据库链接,竟然是只有2,3个数据库链接时,就报上述错误,很是怪异。

一步步删除掉代码,反复试验后,竟然是数据库链接字符串中的 Connect Timeout=0 来作怪的。

比如下述数据库链接字符串就会出现上述问题,

Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=DB1;server=(local);Connect Timeout=0

而把数据库链接字符串修改为
Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=DB1;server=(local)

就不会有问题了。

 

这个bug在微软的反馈中可以看到,如下:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331882&wa=wsignin1.0

其中微软的官方反馈是:

The fix was submitted to the source branch of the next major .Net release.

Microsoft 在 2008/8/15 11:31 发送

照这么说,估计.net 4.0 中会修复这个bug。

 

参考资料:

Why Does a Connection Pool Overflow?
http://msdn.microsoft.com/en-us/library/aa175863%28SQL.80%29.aspx

Trace a SqlConnection - Connection Pooling issues
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Q_22589733.html

Fixing connection pooling timeout exceptions on third-party code
http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=14

Connection Pooling and the "Timeout expired" exception FAQ
http://blogs.msdn.com/angelsb/archive/2004/08/25/220333.aspx

ADO.NET Connection Pooling at a Glance
http://blog.csdn.net/tuwen/archive/2008/05/28/2490299.aspx

FIX: Sp_reset_connection Does Not Reset the Rowcount Settings for the DELETE and UPDATE Statements
http://support.microsoft.com/kb/310617/

ADO.NET数据连接池
http://tech.it168.com/db/s/2006-10-18/200610181013413.shtml

关于ADO.Net连接池(Connection Pool)的一些个人见解
http://www.cnblogs.com/rickie/archive/2004/10/02/48546.aspx

How to: Open Activity Monitor (SQL Server Management Studio)
http://msdn.microsoft.com/en-us/library/ms175518.aspx

Connect Timeout = 0 / Connection Pool Timeout

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331882&wa=wsignin1.0

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值