Timeout Expired when multiple users login to the asp.net applications

BeUnique 2,112 Reputation points
2024-07-01T13:29:08.3033333+00:00

I am developing asp.net application and hosted in the IIS server. when multiple user (more than 300 users+) accessing the applications at very first time all the users getting below 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"

I have handled properly connection opened and closed.

I have increased maxrequestlenth in <httpruntime>

and

i have set max pool size = 50000 in the <connectionstring>

After changing this will be working fine.

Is this correct way to handle the pool connections...?

pls. guide...

 <connectionStrings>
    <clear />
    <add name="Connecion1" connectionString="Data Source=****;Initial Catalog=*****;Persist Security Info=True;User ID=******;Password=******;Max Pool Size=50000;" providerName="System.Data.SqlClient" />
 <system.web>
    <httpRuntime maxRequestLength="2048598" executionTimeout="999999"></httpRuntime>
 </system.web>
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,396 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 28,821 Reputation points Microsoft Vendor
    2024-07-03T06:36:45.67+00:00

    Hi @Gani_tpt,

    The MaxPoolSize property sets the maximum number of connections allowed in the connection pool for this particular connection string. Its default value is 100.

    When multiple users (more than 300 users) access, the default value will be exceeded.

    You can set the MaxPoolSize property to adjust the number of connections, but other than that it's best to check your own code.

    In most cases connection pooling problems are related to connection leaks. Your application probably doesn't close its database connections correctly and consistently.

    What you must do every time your app does db work is to make sure that SqlDataReaders, SqlCommand, SqlConnection objects are closed and disposed of as soon as possible.

    The correct way would be this:

    var connection = new SqlConnection(ConnectionString);
    
    try
    {
         connection.Open();
         someCall (connection);
    }
    catch
    {
        // ...
    } 
    finally
    {
         connection.Close();                
    }
    

    or

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
         connection.Open();
         someCall(connection);
    }
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. SurferOnWww 2,406 Reputation points
    2024-07-03T00:15:25.55+00:00

    Please consider using Async Programing:

    Async Programming : Introduction to Async/Await on ASP.NET

    0 comments No comments