Checking for a lost connection

Checking for a lost connection

I want to periodically check to see if a user’s database connection has been lost. How can I?

First of all, a solution. You can implement periodic ‘polling’ actions by either using the timer OCX on Windows platforms for Version 2, or you can take advantage of the TestCommand() method, which executes several times a second. You can declare a static counter variable and check for the connection every n times. Using the TestCommand() method for any type of complex processing can degrade overall system performance, so use it with care.

The only way to check for an existing database connection is to fire off a SQL statement. You can’t simply test the connection with the IsConnected() method of the session, since that will simply check to see if the client application thinks it’s connected.

However, I would personally advise against using a polling process for this type of check. Why bother to fire off a SQL statement just to test a connection? An easier way to handle this would be to put code into the DBError() method to handle a lost connection. If there is any error in the automatic database access, it will fire the DBError() method, so you can be sure of catching the problem if it occurs. Besides, why bother checking for a lost connection if the user may not even need to access the database? In a client/server system, it’s best to lay back and react to the user’s actions.

See also  Does It Make Sense to Splurge on a Laptop?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist