ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10048)

vrushali picture vrushali · May 25, 2011 · Viewed 7.7k times · Source

I am using the MySQL ODBC (3.51) connector for Windows in my application. I have a loop that continuously opens and closes a connection to my MySQL server running on Localhost. After some time and after successful connections and updates, out of the blue, I get the following exception:

ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10048)

Why is this?

Here is a sample of my code:

for(;i<_queue.Count;i++)
{
  opcdatastructure.opcservertags opctag = _queue.Dequeue();
  update(opctag.value, opctag.filetimestamp, opctag.tagtimestamp, 
         opctag.quality, opctag.itemID);
}

public void update(string value,string filetimestamp,DateTime tagtimestamp,
                   int quality,int itemID)
{
  try
  {
    lock (myLockHolder)
    {
       X1 = 1;
       OdbcConnection con = 
         new OdbcConnection(LocalConnection.GetLocalConnetionString());
       OdbcCommand cmd;                    
       string query = "";
       query = "update parameter" + Environment.NewLine;
       query += "set paramvalue='" + value + "',date_logged1='" + filetimestamp +
                "',Quality='" + quality + "',date_logged='" + tagtimestamp + "'" + 
                Environment.NewLine;
       query += " where itemID='" + itemID + "'";
       if (con.State == ConnectionState.Closed)
           con.Open();
       cmd = new OdbcCommand(query, con);
       cmd.ExecuteNonQuery();
       if (con.State == ConnectionState.Open)
           con.Close();
    }
  }
  catch { }
}

Answer

Renatas M. picture Renatas M. · May 25, 2011