Click here to Skip to main content
12,691,777 members (28,595 online)

error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool

vrushali katkade asked:

Open original thread
public void enqueue(object e)
        DataChangeEventArgs e113 = (DataChangeEventArgs)e;
        for (i=0; i < e113.sts.Length; i++)
            int hour113 = e113.sts[i].TimeStampNet.Hour;
            int minute113 = e113.sts[i].TimeStampNet.Minute;
            int second113 = e113.sts[i].TimeStampNet.Second;
            int millisecond113 = e113.sts[i].TimeStampNet.Millisecond;
            int year113 = e113.sts[i].TimeStampNet.Year;
            int month113 = e113.sts[i].TimeStampNet.Month;
            int day113 = e113.sts[i].TimeStampNet.Day;
            DateTime sdate113 = new DateTime(year113, month113, day113, hour113, minute113, second113, millisecond113);

            DataRow row1 = dt.NewRow();
            row1["itemID"] = e113.sts[i].HandleClient;
            row1["paramvalue"] = convert.ToString(e113.sts[i].DataValue);
            row1["date_logged1"] = sdate113.ToString("dd-MM-yyyy HH:mm:ss.fff");
            row1["Quality"] = e113.sts[i].Quality;
            row1["date_logged"] = DateTime.FromFileTime(e113.sts[i].TimeStamp);
        var threadupdate = new Thread(update);//start new thread & instance
    catch { }

public void update(object dtnew)
                   MySqlConnection con = new MySqlConnection(LocalConnection.GetLocalConnetionStringmysql());
                    DataSet oldvalueds=new DataSet();
                    DataTable newupdateddata = new DataTable();
                    MySqlDataAdapter da;
                    MySqlTransaction trans;
                    if (con.State == ConnectionState.Closed)
                        con.Open();//throws exception
                    trans = con.BeginTransaction();
                    da = new MySqlDataAdapter();
                    da.InsertCommand = new MySqlCommand("INSERT INTO parameter (itemID,paramvalue, date_logged1,Quality,date_logged) " +
                                           "VALUES (@itemID, @paramvalue,@date_logged1,@Quality,@date_logged)" +
                                           "ON DUPLICATE KEY UPDATE " +
                                           "itemID=VALUES(itemID),paramvalue=VALUES(paramvalue),date_logged1=VALUES(date_logged1),Quality=VALUES(Quality),date_logged=VALUES(date_logged)", con);

                    da.InsertCommand.Parameters.Add("@itemID", MySqlDbType.VarChar, 250, "itemID");
                    da.InsertCommand.Parameters.Add("@paramvalue", MySqlDbType.VarChar, 250, "paramvalue");
                    da.InsertCommand.Parameters.Add("@date_logged1", MySqlDbType.VarChar, 250, "date_logged1");
                    da.InsertCommand.Parameters.Add("@Quality", MySqlDbType.VarChar, 250, "Quality");
                    da.InsertCommand.Parameters.Add("@date_logged", MySqlDbType.VarChar, 250, "date_logged");
                   da.InsertCommand.Transaction = trans;
                     DataTable newupdateddt = (DataTable)dtnew;
                  int k = da.Update(newupdateddt);//exception thrown 2nd

            catch(Exception ex) {


It will be thrown an exception like "Error connecting: 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 will be set the timeout=200 in connection string this exception was thrown
"Deadlock found when trying to get lock; try restarting transaction"

Thanks in advance
Tags: C#, .NET, MySQL


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web01 | 2.8.170117.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100