I have some software that grabs information from a mysql server. However, users minimize it to the system tray, and leave it idle for hours until using it again.

If a user leaves the program idling for about 15 minutes, then goes into the program again to perform a query, it throws a Fatal Error in the mysql, and says 'connection must be valid and open'

The reason is simply because the mysql connection has timed out..

I was wondering what the code would be to re-connect to the server IF it has timed out.


I tried simply putting


try
conn.Open()
Catch
End try


so that it tries to connect, and if it can't connect (because the connection is already open), it just carries on, however it does not work, and it still gives an exception because it timed out.

Any ideas?



What would be the connection state once it has timed out? I tried putting it in a thing like


if conn.connectionstate = connectionstate.Closed Or connectionstate.Broken

etc, however it doesn't seem to be working.


Any ideas?

Thanks