Question

Good evening!

I stil have a doubt asp.net connection pooling. I work on a application that sometimes throws the exception "max pool size was reached".

My team looked over and over for some code that was leaking but nothing was found.

But, now it comes my doubt. When it says "max pool size was reached", does it mean that max pool size was reached for the database or for the server?

If SQL Server hosts several databases for several differents asp.net applications, can these others databases interfere in my database (my database is in the same SQL Server). E.g., if there is some application leaking connection, can this leaking generates "max pool size" in my application?

Thanks!

Was it helpful?

Solution

ADO.NET maintains separate connection pool groups per connection string. So if you have multiple databases, they should have their own pools, and those pools should not interfere with each other.

Is it possible that some requests are taking a long time? If enough requests are executed at once against a single database, and they are delayed, maybe the connection pool really is being reached simply because of open connections.

To verify this is not the case, you might check what is running on the database by executing sp_who or by running SQL Server Activity Monitor.

You can also query the DMVs in the database to see how many connections various programs have open by database:

select
    NULL as [Connections by Database],
    [host_name] as [Client Machine],
    DB.name as [Database],
    [program_name] as [Client Program],
    COUNT(*) as [Open Connections]
from sys.dm_exec_sessions s (nolock)
    left join sys.dm_exec_requests r (nolock)
        on r.session_id = s.session_id
    left join sys.databases DB (nolock)
        on DB.database_id = r.database_id
where s.session_id >= 50 -- Ignore SQL Server processes
group by [host_name], DB.name, [program_name]
order by [Client Machine], [Database], [Client Program]

If you did find out that you just need more connections, you can tweak the limit in the connection string by setting the property Max Pool Size to something other than 100. Here is an example.

It is possible to dig through the .NET objects in a debugging heap if you want to see what pool is causing the problem. You would have to capture a memory dump of the w3wp.exe process and analyze it with a tool like WinDbg (or possibly Debug Diagnostics Tool). I have done this in the past. It is not necessarily easy, but it can help a lot.

EDIT

There is a perfmon counter for ADO.NET connection pooling that you can use to monitor leaking connections. In Performance Monitor, cxpand .NET Data Provider for SqlServer and add the counter NumberOfReclaimedConnections. According to the documentation, this counter means:

The number of connections that have been reclaimed through garbage collection where Close or Dispose was not called by the application. Not explicitly closing or disposing connections hurts performance.

We have used this counter to verify our application is leaking connections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top