The Connection Object - Events of the Connection Object
(Page 11 of 15 )
Connection events can be quickly summarized as follows:
- BeginTransComplete is raised after a transaction has begun.
- CommitTransComplete is raised after a transaction has been committed.
- ConnectComplete is raised after the connection has been established.
- Disconnect is raised after a connection has been closed.
- ExecuteComplete is raised after an Execute method call has completed.
- InfoMessage is raised when the provider returns extra information.
- RollbackTransComplete is raised after a transaction has been rolled back.
- WillConnect is raised just before the connection is established.
- WillExecute is raised just before a statement is executed.
These events work in both synchronous and asynchronous modes.
All events will have a bidirectional parameter, adStatus, to indicate the status of the event. This is of type EventStatusEnum, and on entry to the procedure can be one of the following constants:
- adStatusOK indicates that the action that caused the event was successful.
- adStatusErrorsOccured indicates that errors or warnings occurred, in which case the Errors collection should be checked.
- adStatusCantDeny indicates on a Will... event that you cannot cancel the action that generated the event, and on a ...Complete event indicates that the action was cancelled.
- adStatusUnwantedEvent indicates that the action that generated the event should no longer generate events.
On a Will... event (and assuming adStatusCantDeny is not set), before the procedure exits you can set adStatus to adStatusCancel to cancel the action that caused this event. This also generates an error indicating the event has been cancelled. For example, assume that you have moved from one record to the next; this will raise a WillMove event on the recordset. If you decide not to move to another record, you can set adStatus to adStatusCancel, and the Move action will be cancelled. This allows you to cancel actions where the data is incorrect.
When using Will... events, one thing to watch for is implicit method calls. Taking the preceding Move as an example, if the current record has been edited, then ADO implicitly calls Update. In this case you might get more than one Will... event. I discuss this in more detail in Chapter 5.
If you no longer wish to receive events for a particular action, then before the procedure exits, you can set adStatus to adStatusUnwantedEvent, and they will no longer be generated.
This is from ADO Programmer's Reference, by Dave Sussman (Apress, ISBN 1590593421). Check it out at your favorite bookstore today. Buy this book now. |
Next: The BeginTransComplete Event >>
More ASP.NET Articles
More By Apress Publishing