Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Need a work around pon this error

$
0
0

HI,

I am working on a data entry application and while the operator is entering the data, the SQL connection terminates creating the following error. Please check the error below

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.
  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.

My code is:

protected void ItemId_TextChanged(object sender, EventArgs e)
        {
            foreach (RepeaterItem item in Repeater2.Items)
            {

                string ItemId = ((TextBox)item.FindControl("ItemId")).Text;
                if (ItemId != "")
                {
                    string SQLGetTrn;
                    SQLGetTrn = "select ItemName,Cost from IC_Item_M where ItemID = '" + ItemId + "'";
                    SqlConnection con = new SqlConnection(ConString);
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    SqlDataReader ResCd;
                    SqlCommand SelCmd = new SqlCommand(SQLGetTrn, con);
                    ResCd = SelCmd.ExecuteReader();

                    if (ResCd.Read())
                    {
                        if (IsPostBack)
                        {
                            ((TextBox)item.FindControl("ItemName")).Text = Convert.ToString(ResCd["ItemName"]);
                            ((TextBox)item.FindControl("Cost")).Text = Convert.ToString(ResCd["Cost"]);
                        }
                        ResCd.Close();
                    }
                    else
                    {
                        string message = "ItemID: " + ItemId + " does not exist ";

                        string script = "window.onload = function(){ alert('";

                        script += message;

                        script += "')};";

                        ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
                    }
                    con.Close();
                    con.Dispose();

                }
                lblMessage.Visible = false;
                lblMessage2.Text = "";
                lblMessage2.CssClass = "";
            }
        }

Please help me find a solution for this issue. I have closed all the open connections to the DB but still the error occurs. Guide me in this.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>