错误[HY000] [MySQL] [ODBC 3.51驱动程序]无法连接到'localhost'上的MySQL服务器(10048)

时间:2011-05-25 11:31:42

标签: c# .net mysql mysql-error-2003

我在我的应用程序中使用Windows的MySQL ODBC(3.51)连接器。我有一个循环,不断打开和关闭与Localhost上运行的MySQL服务器的连接。经过一段时间,在成功连接和更新之后,我发现了以下异常:

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

为什么会这样?

以下是我的代码示例:

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 { }
}

1 个答案:

答案 0 :(得分:2)