Hi,
I have a problem: The Connector .NET or the Mysql Server does automatically close a connection after a few time. My first step to a solution was to check the Connectionstate before doing a query and reconnect if the connection is broken like this:
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
But I noticed that the ConnectionState doesnt change if the connection is closed(checked it over Mysql workbench). So everytime the connection is closed, I get a System.Exception with the Message "Fatal error encountered during command execution.".
Details of the Exception:
called Method: MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
InnerException.Message: Fatal error encountered attempting to read the resultset.
InnerException.InnerException.Message: "Reading from the Stream has failed"
Doing the next query after the exception was raised, it works fine and it reconnects to the server.
So my question is: Is there any way to Detect when the connection is closed, so that my Query function can do a reconnect if its called?
Sincerely,
Hans
I have a problem: The Connector .NET or the Mysql Server does automatically close a connection after a few time. My first step to a solution was to check the Connectionstate before doing a query and reconnect if the connection is broken like this:
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
But I noticed that the ConnectionState doesnt change if the connection is closed(checked it over Mysql workbench). So everytime the connection is closed, I get a System.Exception with the Message "Fatal error encountered during command execution.".
Details of the Exception:
called Method: MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
InnerException.Message: Fatal error encountered attempting to read the resultset.
InnerException.InnerException.Message: "Reading from the Stream has failed"
Doing the next query after the exception was raised, it works fine and it reconnects to the server.
So my question is: Is there any way to Detect when the connection is closed, so that my Query function can do a reconnect if its called?
Sincerely,
Hans