sunil kumar

sunil kumar

  • NA
  • 6
  • 6.5k

Max pool size reached error

Mar 28 2015 6:01 AM

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)     {         WithThread();     }      private static void WithThread()     {         for (int i = 1; i <= 1500; i++)         {             Thread thread1 = new Thread(new ThreadStart(GetOrders));              thread1.Start();         }     }       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;                  connection.Open();                  using (var reader = command.ExecuteReader())                 {                     while (reader.Read())                     {                         Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));                     }                 }             }         }     }

Can someone help?


Answers (6)