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 { } }
它會拋出一個異常,如「錯誤連接:彙集的連接正在使用中,並且已達到最大池大小。「錯誤連接:超時過期。在從池中獲取連接之前已經超時的時間
我將設置超時= 200在這個異常被拋出 連接字符串「死鎖發現試圖獲取鎖時,請嘗試重新啓動交易」 由於事先
增加池大小是很少一個好主意,通常意味着你掩蓋了與黑客問題(非處理)。如果你的代碼是正確的,你不應該需要這個。 – 2011-05-30 12:11:27
請參閱我的更新 – vrushali 2011-05-30 12:14:18