Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
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
            {

              
            }
        }


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
Posted
Updated 30-May-11 3:00am
v5

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
 
Share this answer
 
v2
please check your database connection and set proper timeout... I think it is set to default...
 
Share this answer
 
Comments
vrushali katkade 30-May-11 8:11am    
please see my updates
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[^]
 
Share this answer
 
v2
Comments
vrushali katkade 31-May-11 0:30am    
when i will be set pooling in connection string it will be throws exception "Input string was not in a correct format."
Kim Togo 31-May-11 2:19am    
Strange. Can you post the connection string you are using?
Kim Togo 31-May-11 2:23am    
What version of MySql Connector/Net are you using ?
vrushali katkade 31-May-11 2:29am    
in connection string i will be set the pool size & then set the pooling=false ,this exception solved but new exception is coming at
int k = da.Update(newupdateddt);this line "too many connections"
Kim Togo 31-May-11 2:43am    
Okay, then I think that the problems is at the server end. In MySql you can limit the maximum connection.
But then, maybe you should rethink your design. Right now your flow is:

Connect -> Begin Transaction -> Update -> End Transaction -> Close

And if you do this many many time very fast, then you create a huge amount of connection to MySql.

On MySql server, try run a "SHOW PROCESSLIST" then you can see how many connections you have.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900