Enterprise Library Data Access – Max Pool Size Reached

A co-worker and I were looking into a recurring problem with one of our oft-used data access web services. It was a problem that had come up at several different customer sites, and the symptoms were always the same. Everything would be working for for x hours, and then we start to get exceptions. Some time later, it starts working again. This process repeats.

Here’s the exception that we’d start to see after some time:

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.

After a big of googling and some experimentation, the cause was found to be an IDataReader that wasn’t being closed properly. After we wrapped it in a using, everything was working just fine. Always make sure to dispose of your IDisposables!