Database Timeout Expired Error on an ASP.NET Application

If you experience the following error when your ASP.NET application connects to the MS SQL server:

System.InvalidOperationException: 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.
It is caused by depleted database connections in the connection pool.   Here are a couple of methods you can use to resolve the problem:

  1. Check your application to make sure all database connections are closed when they are not needed.  ASP.NET is supposed to have garbage collector to reclaim unused resources, however, on a busy site it is likely that the connection pool will run out of connections before garbage collection kicks in.
  2. Raise the connection pool size in the connection string.  For example, you can add "Max Pool Size=100" to your connection string to increase the pool size to 100.