My C# application require reading a value from a remote mysql database.
All seems ok when internet connection is available.
My code works for the above.
However, when there is intermittent internet connection, an error message tends to pop up as attached. Sometime a different error message appear but basically unhandled exception error. I guess one is for connection and one is when mid way executing the query command the connection ended.
I will like to code it such that the message never appears.
I want to be able to know when a connection is available and when it is not,
When available I will like it to continue with what it does, and if not available to ignore it and execute another set of C# commands.
I also need to be able to handle unsuccessful query execution. Will like for it to do another set of C# commands rather then throw out a error message.
Appreciate if someone is able to advise me how to go about these exception handling.
string MyConString = "SERVER="+ servername + ";DATABASE=" + dbname + ";UID=" + uid + ";PASSWORD="+ pwd +";";
using (MySqlConnection connection = new MySqlConnection(MyConString))
using (MySqlCommand command = connection.CreateCommand())
command.CommandText = "select * from pmask where URL='" + axWebBrowser.LocationURL + "'";
Reader = command.ExecuteReader();
string pb1visible = Reader.GetValue(2).ToString();
string pb1top = Reader.GetValue(3).ToString();
string pb1left = Reader.GetValue(4).ToString();
string pb1width = Reader.GetValue(5).ToString();
string pb1height = Reader.GetValue(6).ToString();