Detecting auto-closed/ killed connection
Posted by: Hans Wurst
Date: February 18, 2013 12:46PM

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

Options: ReplyQuote


Subject
Written By
Posted
Detecting auto-closed/ killed connection
February 18, 2013 12:46PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.