从池中获取连接之前超时时间已过 - 但池未满
我什至讨厌提起这个,因为有数百页的页面在讨论这个错误,可以追溯到 7-8 年前……但是,我不太明白这一点。
我在服务器 A 上运行一个报表服务,该服务连接到服务器 B 上的 SQL Server 2008 R2。两台服务器都运行 Windows Server 2008。该报表服务是多线程的,每个报表一次最多运行 10 个报表。
我的连接字符串如下:
Data Source=ServerB;Initial Catalog=DBName;trusted_connection=YES;Connection Timeout=0;Max Pool Size=500;
如您所见,我已将连接超时设置为 0 以等待连接直至其可用,并将最大池大小设置为 500 b/c 我想确保池对于我来说不会太小多线程服务。该错误通常仅在服务启动且有报告队列等待处理时才会显示。
显然,要做的第一件事就是查找泄漏连接.. 必须有未关闭的连接导致池填满,对吗?不 - 看起来游泳池永远不会填满。
过去几个小时我在服务器上运行性能监视器来观察“.NET Data Provider for SqlServer”,并且 NumberOfPooledConnections 从未超过 20 左右。我还在 SQL Server 上运行 perfmon 来监视“SQLServer:General Statistics”,并且 UserConnections 永远不会超过 50。在此期间,我通过手动重新启动服务导致报告此错误 2 或 3 次。
我还能寻找什么?还有什么会导致这个错误? 完整的错误消息是:
System.InvalidOperationException: 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.
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
谢谢, 斯蒂芬
I hate even bringing this up b/c there are so many hundreds of pages talking about this error dating back 7-8 years... However, I cant quite figure this out.
I have a report service running on server A which connects to SQL Server 2008 R2 on Server B. Both servers are running Windows Server 2008. The report service is multi-threaded and runs up to 10 reports at a time each on its own thread.
My connection string is as follows:
Data Source=ServerB;Initial Catalog=DBName;trusted_connection=YES;Connection Timeout=0;Max Pool Size=500;
As you see, I have set the connect timeout to 0 to wait for a connection until its available, and max pool size to 500 b/c I wanted to make sure the pool was not too small for my multi-threaded service. The error typically only shows up when the service starts and there is a queue of reports waiting to be processed.
So obviously, the first thing to do is look for leaking connections.. there have to be connections that are not being closed that are causing the pool to fill up, right? Nope -looks like the pool never fills up.
I have spent the last several hours running Performance Monitor on the server watching ".NET Data Provider for SqlServer" and the NumberOfPooledConnections never gets above 20 or so. I also have perfmon running on the SQL server watching "SQLServer:General Statistics" and UserConnections never goes above 50. During this time, I have caused this error to be reported 2 or 3 times by manually restarting the service.
What else can I look for? What else would cause this error?
Full error message is:
System.InvalidOperationException: 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.
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
Thanks,
Stephen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是已知错误,如此处所示
This is known bug as shown here