Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The timeout period elapsed prior to obtaining a connection from the pool - but the pool is not full

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

like image 342
Stephen Avatar asked Jun 01 '11 20:06

Stephen


People also ask

Is the timeout period elapsed prior to obtaining a connection from the pool?

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. System. InvalidOperationException: Timeout expired.

What is connection timeout in connection pool?

Connection timeoutThis value indicates the number of seconds that a connection request waits when there are no connections available in the free pool and no new connections can be created. This usually occurs because the maximum value of connections in the particular connection pool has been reached.

What happens when connection pool is full?

If the maximum pool size has been reached and no usable connection is available, the request is queued. The pooler then tries to reclaim any connections until the time-out is reached (the default is 15 seconds). If the pooler cannot satisfy the request before the connection times out, an exception is thrown.


1 Answers

This is known bug as shown here

Posted by Microsoft on 8/15/2008 at 11:31 AM Thanks for your feedback. The fix was submitted to the source branch of the next major .Net release.

like image 69
VMAtm Avatar answered Nov 17 '22 01:11

VMAtm