DB Timeout and Session Variables

I have a subclassed MySQLCommunityServer,
I have overwritten the the SQLSELECT select method so it ensures it is connected and it logs any errors with queries. The problem is I have a bunch of MySQLSession variables I set such as “@UserId” etc… that I use in queries to get back proper information. But whenever the session times out and it has to reconnect to the DB, these variables are then wiped.

I figured I could simply rewrite the the Connect method but since “if me.connect then” gets called for every single SqlSelect and SqlExecute, I would rather not be setting these variables every single time.

Is there a way to have the Connect method only set these session variables if the connection is being reconnected?

I have a generic method:
Dim db As MySQLCommunityServer = commonWE.getConnectDB(nil, Session.SQLHost, Session.SQLUsername, Session.SQLPassword, Session.SQLDatabaseName, Session.SQLPort, Session.SQLTimeout, Session.SQLMultiThreaded)
…

When initiating db it is as above. If I want to reconnect to an existing, and maybe timed out db, then I use:
…
db = commonWE.getConnectDB(db, “”, “”, “”, “”, 0, 0, False)
It notices that db exists and tries to reconnect with its existing values.

My problem is that there is no way to tell if the DB is timed out so I don’t want to waste time re-initializing all of the session variables for every database call, but at the same time I need to be able to tell when I do need to re-initialize them.