Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1447

Detecting auto-closed/ killed connection (1 reply)

$
0
0
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

Viewing all articles
Browse latest Browse all 1447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>