Solved

Detecting an ADO Connection loss Event

Posted on 2014-11-17
3
215 Views
Last Modified: 2014-11-18
I have a C++ builder 5 application that uses 4 TADOConnection VCL components in an TDataModule form.
The connections "KeepConnection" property is configured as true so as to keep connected even when there are no datasets open. The application runs 24 hours a day, seven days a week but does not usually process ant data between the hours of 11 pm and 5 am. the database is an SQL Server 2005 database.
Occasionally, there is a loss of connection during the night due to external conditions and I wish to detect this event with an event handler without having to periodically perform data operations to check each connection.
The TADOConnection component has AfterDisconnect and AfterDisconnect event handlers but neither of these are triggered when a disconnection is simulated. Is there a way to detect a loss of connection via an event handler without effectively polling the connection by a read or write data operation ?
I am simulating a loss of connection by connecting the ADO connections through a VPN and disconnecting the VPN.
0
Comment
Question by:alcindor
3 Comments
 
LVL 32

Accepted Solution

by:
ste5an earned 500 total points
ID: 40449258
The disconnect event is called when you close the connection. There is no event for e.g. network problems. Here the old rules apply:

Don't use long living connections.

Otherwise use your own proxy implementation which is able to reconnect.
0
 
LVL 32

Expert Comment

by:sarabande
ID: 40449764
without effectively polling the connection by a read or write data operation ?
polling open connections could be a valid means if you want to show status information (for example count of users connected) anyhow. you could have an own thread for that purpose which would periodically would write some kind of heart beat for all the open connections to the database and would detect loss of connection in addition.

Sara
0
 
LVL 2

Author Comment

by:alcindor
ID: 40449817
Thanks for your comment Sara. I had just accepted ste5an's comment before you posted yours. My alternative plan of action is what you suggested; periodically writing some data or executing some trivial stored procedure.

Roger
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now