Is there an effective way to continuously check if a connection to the database is established? For example, if the network drops or the server computer is turned off, then there is no obvious database available. My idea was to create a Timer
that would poll every 10 seconds or so to determine an available connection but that just seems like another "hack". Another idea is to check connectivity before any user input. Here is the sample code that would check for a connection:
public bool isDbAvail()
{
using (MySqlConnection conn = new MySqlConnection(TimeClock.Properties.Settings.Default.timeclockConnectionString))
{
try
{
conn.Open();
return true;
}
catch (MySqlException ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
Any input would be great on what would be the best approach.