ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10048)
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.开发者_如何学JAVAquality, 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 { }
}
This page might shed some light on the problem you are experiencing:
Troubleshooting the error: ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10048)
精彩评论