3

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?

Curtis
  • 101,612
  • 66
  • 270
  • 352
  • how about find the open connections as you run your pages and see if they stay stable, or increasing ? http://stackoverflow.com/questions/216007/how-to-determine-total-number-of-open-active-connections-in-ms-sql-server-2005 – Aristos May 18 '12 at 15:51
  • 2
    I'd check the server to see if there was a bunch of open connections and then enable profiler for a few minutes to see the last few commands issued by an open connection on the server. Hopefully seeing the last commands will give you a clue where to look in your code. – Zachary May 18 '12 at 15:57

1 Answers1

1

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.

JerKimball
  • 16,584
  • 3
  • 43
  • 55