Using Performance Monitor to monitor pooled connections

VincentH picture VincentH · Aug 16, 2013 · Viewed 17.7k times · Source

I'm investigating this error from a MVC3 application that is failing under load:

"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."

The application is using the Repository pattern and Entity Framework, and my hunch is that it's not closing off connections properly. I want to be able to monitor the number of pooled connections on the SQL Server. Searching around leads me to believe that I can use these counters in Perfmon:

  • .NET CLR Data
  • .NET Data Provider for SQLServer

However both of them show and being disabled / grayed out.

I am running Perfmon directly on the server, and both ISS and SQL Server are running on the server. Any ideas why these counters would not be available?

I've also tried using SQL Profiler to monitor pooled connections, but the EventSubClass column isn't available for AuditLogin.

Answer

Brian picture Brian · Aug 16, 2013

You can run this from a SQL query windows to get a count and the details of current connections and session running on your SQL server.

select * FROM sys.dm_exec_sessions AS es  
INNER JOIN sys.dm_exec_connections AS ec  
ON es.session_id = ec.session_id

I've had trouble with pooled connections. They're hard to control. Explicitly closing them never seemed to work since they're under the control of .NET. The biggest reason we've run out of connections is uncommitted transactions. If a transaction is left uncommitted or rolled back for some reason, the connection, instead of being re-used, get's stuck in limbo, forcing .NET to open yet another connection to continue processing.