I’m seeing the dreaded “The timeout period elapsed prior to obtaining a connection from the pool” error.
I’ve searched the code for any unclosed db connections, but couldn’t find any.
What I want to do is this: the next time we get this error, have the system dump a list of which procs or http requests are holding all the handles, so I can figure out which code is causing the problem.
Even better would be to see how long those handles had been held, so I could spot used-but-unclosed connections.
Is there any way to do this?
There are some good links for monitoring connection pools. Do a google search for “.net connection pool monitoring”.
One article I referred to a while back was Bill Vaughn’s article (Note this is old but still contains useful info). It has some info on monitoring connection pools, but some great insights as to where leaks could be occuring as well.
For monitoring, he suggests;
Edit:
As always, check out some of the other similar posts here on SO
Second Edit:
Once you’ve confirmed that connections aren’t being reclaimed by the pool, another thing you could try is to utilise the StateChange event to confirm when connections are being opened and closed. If you are finding that there are a lot more state changes to opened than to closed, then that would indicate that there are leaks somewhere. You could also then log the data in the statechanged event along with a timestamp, and if you have any other logging on your application, you could start to parse the log files for instances where there appears to be state changes of closed to open, with no corresponding open to closed. See this link for more info on how to handle the StateChangedEvent.