Max pool size reached error

Posted by Pvsk123 under ADO.NET on 3/28/2015 | Points: 10 | Views : 422 | Status : [Member] | Replies : 1
I have a console application where i want to use threads. In the thread i am opening connection where at some point of time it breaks with the error "The timeout period elapsed prior to obtaining a connection from the pool".

Here is my connection string

connectionString="Data Source=INBLRWIT058068\SQL2008R2;Initial Catalog=OMApp;Integrated Security=SSPI;Pooling=True;Min Pool Size=500;Max Pool Size=2000" providerName="System.Data.SqlClient"

Here is the C# code

static void Main(string[] args)

private static void WithThread()
for (int i = 1; i <= 1500; i++)
Thread thread1 = new Thread(new ThreadStart(GetOrders));

public static void GetOrders()
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
using (SqlCommand command = new SqlCommand("dbo.GetOrders", connection))
command.CommandTimeout = 2;
command.CommandType = CommandType.StoredProcedure;


using (var reader = command.ExecuteReader())
while (reader.Read())
Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));
Can someone help?


Posted by: Jitendrasoft09 on: 3/28/2015 [Member] [MVP] Starter | Points: 25


Please find below details for the solutions-

* Check against any long running queries in your database.
* Increasing your pool size will only make your webapp live a little longer (and probably get a lot slower)
* You can use sql server profiler and filter on duration / reads to see which querys need optimization.
* I also see you're probably keeping a global connection?

Please refer below link for more details-

Jitendra Kumar
If my post helps you, plz mark as an answer.

Pvsk123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response