-3

我在我的应用程序中使用适用于 Windows 的 MySQL ODBC (3.51) 连接器。我有一个循环,不断打开和关闭与运行在Localhost. 一段时间后,在成功连接和更新之后,出乎意料的是,我得到以下异常:

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

1 回答 1

2

此页面可能会阐明您遇到的问题:

排除错误:错误 [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10048)

于 2011-05-25T11:48:13.683 回答