Answer on you question is - IsConnected returns true when connection was established in the past and was not closed. Even in the case of error in any SQL query execution IsConnected will return true until you close the connection.
There are many methods to test if connection is still there. The easiest way - execute simple SQL query and just look if execution was successful - you can use TSQLServer::Exec() method for that (try SQL command COMMIT or SHOW STATUS, for instance). Another possibility is to use TSQLServer::HasTable() method, which also sends request to the server each time when called. Of course, you should knew the name of existing table.
I already investigated such an option (make a simple query). The problem with this is that if the connection has been dropped, this operation takes a long time to return. What I need is something quick.
Is there some thing (I have looked around in the documentation quite a bit) which allows me specify a timeout for a query. Like, if there has been no return from the Query in 1 second dis-continue attempting to send the query.
First of all, thank you so much for helping me out with this.
I am connecting to a MySQL DB.
The application I am developing I am just testing in my lab. It will be running on a machine which will be wirelessly connected to a private network which hosts the DB machine also.
Do you have network problems or SQL server is hanging?
It is likely that I will encounter network problems when the code is running in the real world scenario. Currently I am testing the codes behavior in this environment by plugging and unplugging the ethernet cable in/out of my machine here in the lab.
My current solution is to ping the server with the following function
Can you try to use another version of TMySQLServer.cxx, attached to this message. I add two new options - read_timeout and write_timeout, which you can specify in URL like this:
This should set read and write timeouts to 10 seconds. If it helps for your case, I will submit changes to repository. But, seems to be, this will work only with the newest (6.0 alpha) version of mysql or on the Windows. Anyway, you can try.