On a production system, I occasionally find the following error in the log:
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.
In order to remedy this I increased the maximum pool size to an outrageously high 10,000:
connectionString="metadata=res:///MyEntities.csdl|res:///MyEntities.ssdl|res://*/MyEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=MyDb;integrated security=True;MultipleActiveResultSets=True;Max Pool Size=10000;App=My Service""
But the problem still occurs. What other causes could there be to this error, other than the connection pool being maxed out?
EDIT: before anyone else suggests it, I do always use using(...) { }
blocks whenever I open a connection to the DB, e.g.:
using (var db = new MyEntities())
{
// do stuff
}