Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

we have developed a application in ASP.NET when multiple user login together we got error

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

so how to over come this problem .need help.

What I have tried:

I tried max pool limit in connection string .,pooling on;
Posted
Updated 23-Jan-18 3:40am
Comments
Laxmidhar tatwa technologies 23-Jan-18 9:20am    
sir comnnection pool has a limit but object pool has no limit
mr_busy 25-Jan-18 4:49am    
can you please give code snippet for object pool
Dave Kreskowiak 23-Jan-18 9:32am    
Without seeing your code, it's impossible to tell you what you're doing wrong. From the error message, it sounds like you're not handling your database connections properly.
Laxmidhar tatwa technologies 30-Jan-18 8:53am    
It is difficult to tell without observing band width,database structure and connection

1 solution

Probably, you are handling SqlConnection objects badly: if you do not close and dispose them when you are finished with them they will remain open until the Garbage Collector gets fired up because your app runs out of memory, or your app closes - whichever happens first. If you exhaust the connection pool before the GC does anything, or your app closes, you will get this error.
The simplest way around this is to always enclose your SqlConnection objects in a using block:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT Id, description FROM myTable", con))
        {
        using (SqlDataReader reader = cmd.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["Id"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", id, desc);
                }
            }
        }
    }
When you do that, the connection is Closed and Disposed automatically when the variable goes out of scope, so your connections do not get left around for the GC. Note that SqlCommand objects and such like are also scarce resources and should be treated the same way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900