I have read:
- https://blogs.msdn.microsoft.com/sql_pfe_blog/2013/10/08/connection-pooling-for-the-sql-server-dba/
- https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-connection-pooling
but am no closer to understanding or resolving my issue which is as follows. I have posted here instead of at dba.stackexchange.com for no other reason than I believe this will receive a bigger readership.
This is also not your typical make sure you close your connections with a using clause as no matter whether the stored proc is run from SQL Agent, SQL Server Management Studio or via an external application which is not an ASP.NET application I see this behaviour.
My environment is as follows:
- SQL Server 2012 - 11.0.2100.60 (X64) Standard
- Windows Server 2008 SP2, IIS 7
The SQL Server and IIS are all running on the same machine.
I have the following intermittent problem where a particular stored procedure runs that is resource intensive (definitely CPU 100%, I/O is hard to measure) and occasionally causes a web forms application to stop responding to requests.
The webforms application is running in its own application pool (with default settings so 100 data connections max) and the way to recover things is to restart the application pool which cleans up the connection pool. Very occasionally if you wait long enough (say 5+ minutes) the connection count drops and things recover, but this is not consistent.
To isolate this stored procedure from the webforms app I changed the connection string for the stored procedure so that it had its own application name as I thought (from my reading) that it would keep it from interfering with the webforms application but the behaviour persists which is that I see the following in the event log:
A number of these:
Exception information:
Exception type: EntityException
Exception message: The underlying provider failed on Open.
ultimately followed (some time later) by:
Exception information:
Exception type: InvalidOperationException
Exception message: 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.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at which point the website has stopped serving up requests. Looking at what is being reported by SQL Server via:
SELECT COUNT(*) FROM sys.dm_exec_sessions
I see a larger number than usual of connections.
So assuming I have no opportunity to change the stored procedure, can anyone tell me what is happening here because clearly I have some kind of gap in my understanding. And if possible how I go about fixing this issue?