Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

Transactions

Transactions enable you to perform several different operations on a database that are executed as a single, atomic operation. This is very useful in cases in which you want to update several tables, but only if all the updates are performed successfully. Transactions can help you avoid the ill effects of partially completed operations if one of the updates should fail.

To begin a transaction on a connection, call its ADOConnection.BeginTrans() method, which takes no parameters. You can then perform any changes to the datasource that you want to be a part of the transaction.

If all goes well and you want to save all the changes to the database, you should call the connection's ADOConnection.CommitTrans() method. If something goes wrong or you just change your mind, you can call ADOConnection.RollbackTrans(), which will undo any changes since the call to ADOConnection.BeginTrans().

After you call ADOConnection.CommitTrans() or ADOConnection.RollbackTrans() to end a transaction, ADO might not automatically start a new transaction for you. This is controlled by setting the Attributes property of the ADOConnection. If you include adXactCommitRetaining in Attributes, a new transaction will be started for you after a call to ADOConnection.CommitTrans(). Similarly, including adXactAbortRetaining starts a new transaction after a call to ADOConnection.RollbackTrans().

Share ThisShare This

Informit Network