我在我的应用程序中使用适用于 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 { }
}