Question

I have an ASP.NET Web Application which is occassionally returning the following, irritating, error:

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.

My manager suspects this is because of an unclosed SqlConnection within the application. Therefore I'm currently manually checking through every single code file in the application to see if any connections were left open.

Is there a quicker solution to finding the root of this error?

Was it helpful?

Solution

Bunch of different options:

  • Use Resharper and its "search with pattern" (also called "Structural Search"): http://blogs.jetbrains.com/dotnet/2010/04/introducing-resharper-50-structural-search-and-replace/

  • Write a miniature syntax tree walker for FxCop or Roslyn to perform the same search (basically, a new SqlConnection not disposed)

  • Write a wrapper class for SqlConnection (more common than you might think), and track open/closed connections in there.

  • Attach WinDbg to a "live" or ideally erroring application, and walk your heap objects back to where they are rooted from.

  • Grab a proper profiler (SciTech is a neat one) that will give you call stacks for object creation.

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