Click here to Skip to main content
15,867,328 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
When I logged into my webpage and logout,,and again login and logout with another password and user and password..again again... Its shows the following error:

System.InvalidOperationException: 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. at Bal_Login.CheckDummy() in ...


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.
Posted
Updated 13-Nov-15 2:29am
v5
Comments
Mehdi Gholam 13-Nov-15 5:53am    
The error seems pretty clear, and where you should focus...
Arasappan 13-Nov-15 5:57am    
onnum purila ne vera....pretty clearnu.. (I dont know what the error is)
Sinisa Hajnal 13-Nov-15 6:28am    
It means that all your connections are busy. You might check how you use connections (maybe you're not closing after using it) and how is your connection pool set up.
ZurdoDev 13-Nov-15 7:31am    
You likely aren't closing your connections after you ExecuteNonQuery or ExecuteReader()m etc.
Arasappan 13-Nov-15 8:25am    
aLL CONNECTIONS ARE CLOSE

1 solution


Following my earlier comment, here is a formatted version of your code wherein I use the using statement.


C#
protected void ImgLogin_Click ( object              sender,
                                ImageClickEventArgs e )
     {
     try
        {
        string  command_string;
        string  connection_string;

        command_string = "SELECT * " +
                         "FROM tbl_login_user " +
                         "WHERE username=@username AND " +
                               "password=@password";
        connection_string = ConfigurationManager.
                            ConnectionStrings [ "constrings" ].
                            ConnectionString;
        using ( SqlConnection SQL_connection =
                              new SqlConnection (
                                      connection_string ) )
            {
            SQL_connection.Open ( );
            using ( SqlCommand SQL_command =
                               new SqlCommand (
                                       command_string,
                                       SQL_connection ) )
                {
                SQL_command.Parameters.AddWithValue (
                                           "@username",
                                           txtusername.Text );
                SQL_command.Parameters.AddWithValue (
                                           "@password",
                                           txtpwduser.Text);
                using ( SqlDataReader SQL_data_reader =
                                      SQL_command.
                                          ExecuteReader ( ) )
                    {
                    SQL_data_reader.Read ( );
                    if ( SQL_data_reader.HasRows )
                        {
                        Response.Redirect (
                                     "~/Adminlogin/home.aspx",
                                     false);
                        }
                    else
                        {
                        msg.ShowAlertMessage (
                                "Invalid Login Credentials" );
                        }
                    }
                }
            }
        }
    catch ( Exception ex )
        {
        Response.Write ( ex.ToString ( ) );
        }
    }


SQL_connection, SQL_command, and SQL_data_reader will all be closed at the end of each's using statement block.



In place of the using statements, you could use a single finish block to insure that all object opened in the try block are closed.

 
Share this answer
 
v2
Comments
Arasappan 17-Nov-15 0:02am    
It run perfectly in local database.not in online db
gggustafson 17-Nov-15 10:29am    
That implies that the problem may be environmental. You should insure that the environment on the development machine is the same as the environment on the server.
Arasappan 17-Nov-15 1:58am    
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: 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.

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