Skip to content
June 21, 2011 / kiranpatils

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occured because all pooled connections were in use and max pool size was reached.


Have you seen following error?


Then this post is to solve it!


As per the error your code has not closed the opened SqlConnection properly. For example

SqlConnection conn = new SqlConnection(

doSomething(); /*  If some error occurs here — Next line will not get called and it will leave connection open */


SqlConnection conn = new SqlConnection(myConnectionString);
conn.Close();    // This line will get called in any case — success/failure

So, open your solution in Visual Studio and search in entire solution for all open connections and for all the code implement above suggested solution.

Just a note : If you have written Data Access layer code in code behind file then you are in trouble here. You have to do changes at N number of places. If you would have created separate Data Access layer (Technically Class Library) and Method to do DB operation then your task would have been easy enough!
2) You can 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.

Implement above solutions. You should not see any issues any more.

Good to read :
Happy DB Access! 🙂


Leave a Comment
  1. Manaday Mavani / Jun 27 2011 5:40 am


    I think it’s better to pre check the connection state in the finally block like –

    if(connectionState.Open == conn.State)

    or another efficient way is write whole code in using keyword

    using (SqlConnection conn = new SqlConnection)


    } // Connection is disposed and closed here, even if an exception is thrown

    Very good to read :

    • kiranpatils / Jun 29 2011 3:11 am

      Yes — Agree! Using is best!

  2. Karnail Singh / Jul 31 2013 10:00 am

    Very Nice

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: