RAD Studio |  |

ADO Connection Events
Events when establishing a connection | Events when disconnecting | Events when managing transactions | Other events | See Also
Collapse All

In addition to the usual events that occur for all database connection components, TADOConnection generates a number of additional events that occur during normal usage.

Events when establishing a connection

In addition to the BeforeConnect and AfterConnect events that are common to all database connection components, TADOConnection also generates an OnWillConnect and OnConnectComplete event when establishing a connection. These events occur after the BeforeConnect event.

- OnWillConnect occurs before the ADO provider establishes a connection. It lets you make last minute changes to the connection string, provide a user name and password if you are handling your own login support, force an asynchronous connection, or even cancel the connection before it is opened.
- OnConnectComplete occurs after the connection is opened. Because TADOConnection can represent asynchronous connections, you should use OnConnectComplete, which occurs after the connection is opened or has failed due to an error condition, instead of the AfterConnect event, which occurs after the connection component instructs the ADO provider to open a connection, but not necessarily after the connection is opened.

Events when disconnecting

In addition to the BeforeDisconnect and AfterDisconnect events common to all database connection components, TADOConnection also generates an OnDisconnect event after closing a connection. OnDisconnect occurs after the connection is closed but before any associated datasets are closed and before the AfterDisconnect event.

Events when managing transactions

The ADO connection component provides a number of events for detecting when transaction-related processes have been completed. These events indicate when a transaction process initiated by a BeginTrans, CommitTrans, and RollbackTrans method has been successfully completed at the data store.

- The OnBeginTransComplete event occurs when the data store has successfully started a transaction after a call to the BeginTrans method.
- The OnCommitTransComplete event occurs after a transaction is successfully committed due to a call to CommitTrans.
- The OnRollbackTransComplete event occurs after a transaction is successfully aborted due to a call to RollbackTrans.

Other events

ADO connection components introduce two additional events you can use to respond to notifications from the underlying ADO connection object:

- The OnExecuteComplete event occurs after the connection component executes a command on the data store (for example, after calling the Execute method). OnExecuteComplete indicates whether the execution was successful.
- The OnInfoMessage event occurs when the underlying connection object provides detailed information after an operation is completed. The OnInfoMessage event handler receives the interface to an ADO Error object that contains the detailed information and a status code indicating whether the operation was successful.

See Also

Connecting to Databases

Connecting to a Data Store Using TADOConnection

Connecting to a Data Store Using TADOConnection

Accessing the Connection's Datasets

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!