错误连接:超时已过期.从池中获取连接之前经过的超时时间

错误连接:超时已过期.从池中获取连接之前经过的超时时间

问题描述:

public void enqueue(object e)
{
    try
    {
        DataChangeEventArgs e113 = (DataChangeEventArgs)e;
        resetdatasource();
        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);
            dt.Rows.Add(row1);
        }
        var threadupdate = new Thread(update);//start new thread & instance
        threadupdate.Start(dt);
    }
    catch { }
}

public void update(object dtnew)
        {
            try
            {
                   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
                       trans.Commit();
                       con.Close();

              }
        
            catch(Exception ex) {
             
               }
            finally
            {

              
            }
        }



它将引发异常,例如错误:连接超时:超时.从池中获取连接之前已经过了超时时间.这可能是因为所有池中的连接都在使用中,并且已达到最大池大小."

我将在抛出异常的连接字符串中设置timeout = 200
尝试获取锁时发现死锁;尝试重新启动事务"

在此先感谢



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

超时已过期.从池中获取连接之前已过超时时间

由于您可能没有将您的数据库保存在正确的位置,因此也可能导致此错误.

我认为首先将超时设置为默认.然后将您的数据库保存在正确的位置.关闭您的数据库,然后尝试检查您的应用程序以进行更新查询.这可以解决您的超时问题

问候
Amul VV Wayangankar
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool

This error may also cause because u may not have saved ur database at proper location.

I think firstly set timeout to Default. Then save your database at proper location.Close ur database and then try to check ur application for Update query.This may solve ur timeout problem

Regards
Amul V V Wayangankar


请检查您的数据库连接并设置适当的超时...我认为它已设置为默认值...
please check your database connection and set proper timeout... I think it is set to default...


尝试禁用连接池,看看您的代码如何工作.

Pooling=false

也许更改Connection LifetimeMax Pool Size

有关有效的连接字符串,请参见MySql的链接. http://dev.mysql.com/doc/refman/5.5/zh_CN/connector-net-connection-options.html [ ^ ]
Try to disable Connection pool and see how your code is working.

Pooling=false

Perhaps change Connection Lifetime or Max Pool Size

See link from MySql about connection string that is valid. http://dev.mysql.com/doc/refman/5.5/en/connector-net-connection-options.html[^]