What is a proper way to check at query time if the connection has been lost? This is the code where I'd like to have this, I just can't figure out how to do it. I do get a query error but that's too general, I can't assume that a query error is loss of connectivity. (in my case it most likely will be though). I *could* do a string search but that seems dirty as the error messages may vary.
public bool Query(string query)
{
/* if(m_con.State != m_con.ConnectionState.Open)
{
ThrowError("query...","Seem to have lost connection, will try to reconnect...");
try
{
m_con.Open();
}
catch
{
ThrowError(query,"FATAL:Unable to connect to DB");
return false;
}
}*/
try
{
if(m_Reader!=null) m_Reader.Close();
MySqlCommand command = m_con.CreateCommand();
command.CommandTimeout = 0;
command.CommandText = query;
m_Reader = command.ExecuteReader();
}
catch (Exception ex)
{
string exstr=ex.ToString()
/*
if( Connection is lost )
{
//handle properly
//set flag to mark this connection as lost so it can try to reconnect later
return false;
}*/
ThrowError(query,exstr);
return false;
}
Debugger.Write(String.Format("mysql{0}",m_conid),"Query:{0}",query);
return true;
}
public bool Query(string query)
{
/* if(m_con.State != m_con.ConnectionState.Open)
{
ThrowError("query...","Seem to have lost connection, will try to reconnect...");
try
{
m_con.Open();
}
catch
{
ThrowError(query,"FATAL:Unable to connect to DB");
return false;
}
}*/
try
{
if(m_Reader!=null) m_Reader.Close();
MySqlCommand command = m_con.CreateCommand();
command.CommandTimeout = 0;
command.CommandText = query;
m_Reader = command.ExecuteReader();
}
catch (Exception ex)
{
string exstr=ex.ToString()
/*
if( Connection is lost )
{
//handle properly
//set flag to mark this connection as lost so it can try to reconnect later
return false;
}*/
ThrowError(query,exstr);
return false;
}
Debugger.Write(String.Format("mysql{0}",m_conid),"Query:{0}",query);
return true;
}