ADO Connection Events
Go Up to Connecting to ADO Data Stores
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.
- Data.Win.ADODB.TADOConnection.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.
- Data.Win.ADODB.TADOConnection.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 Data.Win.ADODB.TADOConnection.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 Data.Win.ADODB.TADOConnection.OnBeginTransComplete event occurs when the data store has successfully started a transaction after a call to the BeginTrans method.
- The Data.Win.ADODB.TADOConnection.OnCommitTransComplete event occurs after a transaction is successfully committed due to a call to CommitTrans.
- The Data.Win.ADODB.TADOConnection.OnRollbackTransComplete event occurs after a transaction is successfully aborted due to a call to RollbackTrans.
ADO connection components introduce two additional events you can use to respond to notifications from the underlying ADO connection object:
- The Data.Win.ADODB.TADOConnection.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 Data.Win.ADODB.TADOConnection.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.