For years, I\'ve experienced very weird problems on all my web applications that connect to a SQL server.
The problem is that if something happens to the database server
I did some similar research into connection pooling a while ago, for a slightly different reason, but hopefully will be of some use. What I found is:
Connections are automatically removed from the pool, my findings were that this typically occurred within a few minutes after it was last used. So, it may be a timing issue - and they are being cleared up, but not before the connections are attempted to be reused again.
These were some articles I looked at, at the time:
Sql Server Google Group
Using Connection Pooling in ASP.NET
Edit:
It does sound odd that the bad connection stays in the pool forever - are you sure it definitely does, and it's not just multiple bad connections? If you are sure then it sounds like those connections aren't being released properly within your code. This is another very good article I read a while ago, that says (quote):
Automatically Flushing Connections
If a pooled connection remains in the “closed but reusable” state for between 4 and 8 minutes (an interval chosen at random) the connection pooling mechanism closes the physical connection and discards the pooled connection. That is unless the number of remaining connections is greater than the minimum connections configured for the pool (the default is 0). Note that a connection must have been closed by the application (and released back to the pool) before it can be subject to automatic release. If you don’t close the connection in code or orphan the Connection object, the pooling mechanism will do nothing. No, there are no ConnectionString arguments to change the timeout value.
We've seen the same problem from C++ using ADO. A few years ago, after working with Microsoft Support, we also implemented similar retry logic in the code and reset the connection pool which resolved the problem.
If there is a better workaround the folks at Microsoft Support either didn't know it, or weren't sharing (At that time anyways).