I ask because since we started using If Not db.IsConnected Then db.Connect in our code, our database seems to start getting
Can’t connect to MySQL server on ‘…’ (10060)
errors after a short period of time.
We can’t be sure (it would be hard to explain why), but it seems that these messages only started appearing when we started using this new IsConnected feature.
Before using this new feature, we only used db.Connect after a minimum timeout at important points in the code. Back then, we didn’t have any 10060 errors.
In the past you would call Connect, then another call to see if the dbase opened/connected successfully. Now Connect both opens the connection and returns a boolean that tells you whether or not it was successful.
You seem to be confusing API 1.0 and API 2.0 database methods.
In API 1.0 Database.Connect returned a Boolean and developers were responsible for checking the ErrorCode. Now, in API 2.0, Database.Connectdoes not return a Boolean, and will raise a DatabaseException with the error information.
You’re mixing APIs. API 1.0 still exists, but Connect was not renamed the way most API 2.0 functions were (such as Mid becoming Middle and changing offsets).
Connect as Boolean the API 1.0 variant. The signature you use changes which API is being used. If using the API 1.0 signature were to suddenly raise exceptions or not compile that would break existing API 1.0 code.
What I said is correct. If you are using call DB.Connect or var b as Boolean = DB.Connectyou are using API 1.0.
I just wanted to point out that all of your code can be APIv2 compatible and an:
If db.Connect Then
...
End If
would be executed without errors, but the exception that you might expect and handle between Try..Catch...End Try would not be thrown.
But all of this doesn’t answer my actual question. Even though it has now become clear that our problem has nothing to do with IsConnected, I would still like to know what exactly IsConnected does.
Seems to me it doesn’t do anything. Its a property of a connection. You query it to see if the connection is still open. And I imagine its API2 only.
Personally I have wrappers for all the main database methods, within which I handle errors and, just as importantly the logging of errors. This meant that changing from database API1 stuff to API2 took me about 15 minutes.
For MBS Xojo SQL Plugin and the SQLDatabaseMBS class, the IsConnected property just checks flags for whether there is a connection, not whether the connection is alive.
This is different for the isAlive property:
For Sybase, SQLBase, MS SQL Server, Oracle, ODBC, MySQL, MariaDB, DB2, CubeSQL, Informix, Interbase, FireBase and PostgreSQL we check the status of the connection. This may send a query over the network and sees if server responds properly. If network connection breaks, this function returns false.
For SQLite, DuckDB and SQL Anywhere we return true if we are connected, just like isConnected property.