Lost Connection to MySQL Server during query
Posted: Sun 28 Feb 2010 03:22
We very frequently get "Lost Connection to MySQL Server during query" at seemingly random places and at random times. Usually the error happens when interacting with a MySQL server over the Internet, but it also occasionally happens with local servers.
I have done a few things just now to try to handle this and I would like your input:
--- On the connection object, I did this:
ConnectionTimeout=60
LocalFailover = true
ConnectionLost += new Devart.Common.ConnectionLostEventHandler(mySqlconnection_ConnectionLost);
ConnectionString += "Connection LifeTime=600;"
--- The ConnectionLost event handler
void mySqlconnection_ConnectionLost(object sender, Devart.Common.ConnectionLostEventArgs e)
{
string message = string.Format("ConnectionLost: Cause: {0}, Context: {1}", e.Cause.ToString(), e.Context.ToString());
LogUtil.Log.Error(message);
if (_retryCount++ < 5) // _retryCount is a class-level variable in my provider factory
{
LogUtil.Log.Info("Retrying (retry count: " + _retryCount + ")");
e.RetryMode = Devart.Common.RetryMode.Reexecute;
}
else
{
LogUtil.Log.Info("Giving up (retry count: " + _retryCount + ")");
e.RetryMode = Devart.Common.RetryMode.Raise;
_retryCount = 0;
}
}
--- On the MySQL Server, I have requested this (not yet done):
connect_timeout=30 (default is 5)
net_read_timeout=60 (default is 30)
net_write_timeout=120 (default is 60)
My main question is on my LostConnection event handler. I am simply always retrying 5 times, no matter what. But the example in your help file is different and much more conservative:
if (e.Cause == ConnectionLostCause.Execute)
{
if (e.Context == ConnectionLostContext.None)
e.RetryMode = RetryMode.Reexecute;
else
e.RetryMode = RetryMode.Raise;
}
else
e.RetryMode = RetryMode.Raise;
Could you let me know why the example from your help file only re-executes when e.Cause==ConnectionLostCause.Execute and e.Context ==ConnectionLostContext.None? Also, Is there any issue with the way I wrote my event handler?
Anything else you can recommend to fix the issue?
Thanks,
Lars
Ps. I am using version 5.40.37
I have done a few things just now to try to handle this and I would like your input:
--- On the connection object, I did this:
ConnectionTimeout=60
LocalFailover = true
ConnectionLost += new Devart.Common.ConnectionLostEventHandler(mySqlconnection_ConnectionLost);
ConnectionString += "Connection LifeTime=600;"
--- The ConnectionLost event handler
void mySqlconnection_ConnectionLost(object sender, Devart.Common.ConnectionLostEventArgs e)
{
string message = string.Format("ConnectionLost: Cause: {0}, Context: {1}", e.Cause.ToString(), e.Context.ToString());
LogUtil.Log.Error(message);
if (_retryCount++ < 5) // _retryCount is a class-level variable in my provider factory
{
LogUtil.Log.Info("Retrying (retry count: " + _retryCount + ")");
e.RetryMode = Devart.Common.RetryMode.Reexecute;
}
else
{
LogUtil.Log.Info("Giving up (retry count: " + _retryCount + ")");
e.RetryMode = Devart.Common.RetryMode.Raise;
_retryCount = 0;
}
}
--- On the MySQL Server, I have requested this (not yet done):
connect_timeout=30 (default is 5)
net_read_timeout=60 (default is 30)
net_write_timeout=120 (default is 60)
My main question is on my LostConnection event handler. I am simply always retrying 5 times, no matter what. But the example in your help file is different and much more conservative:
if (e.Cause == ConnectionLostCause.Execute)
{
if (e.Context == ConnectionLostContext.None)
e.RetryMode = RetryMode.Reexecute;
else
e.RetryMode = RetryMode.Raise;
}
else
e.RetryMode = RetryMode.Raise;
Could you let me know why the example from your help file only re-executes when e.Cause==ConnectionLostCause.Execute and e.Context ==ConnectionLostContext.None? Also, Is there any issue with the way I wrote my event handler?
Anything else you can recommend to fix the issue?
Thanks,
Lars
Ps. I am using version 5.40.37