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?
Rajeesh MenothPosted Mar 30, 2015, 6:27 AM
Try this..
1) http://stackoverflow.com/questions/23731876/timeout-expired-the-timeout-period-elapsed-prior-to-obtaining-a-connection-from
2) http://www.sqlservercentral.com/blogs/querying-microsoft-sql-server/2013/09/13/connection-pool-limit-exceeds-error/
sunil kumarPosted Mar 30, 2015, 6:21 AM
Rajeesh MenothPosted Mar 30, 2015, 5:21 AM
sunil kumarPosted Mar 30, 2015, 12:30 AM
Riddhi ValechaPosted Mar 28, 2015, 8:25 AM
One Solution is -
SQLConnection.ClearAllPools();
--
Use this static method...
Rajeesh MenothPosted Mar 28, 2015, 7:30 AM
connectionString="Data Source=INBLRWIT058068\SQL2008R2;Initial Catalog=OMApp;Integrated Security=SSPI;Pooling=True;Min Pool Size=500;Max Pool Size=6000" providerName="System.Data.SqlClient"