错误 [HY000] [MySQL][ODBC 3.51 驱动程序]无法连接到“localhost”上的 MySQL 服务器(10048)
我在我的应用程序中使用适用于 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 { }
}
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 { }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此页面可能会阐明您遇到的问题:
This page might shed some light on the problem you are experiencing: