NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Doing transactions

Database transactions are used to control data commitment to databases. For example, in standard account procedures, it is necessary to debit one account and credit another at the same time. Since computers fault on occasion (power outages, network outages, etc.) there is a potential for one record to be updated/added, but not the other. To avoid these situations we use transactions. Transactions in ADO+ are, just as in ADO, handled at the database level: your database must support transactions.

There are three basic commands for transactions: begin, commit and rollback. "Begin" marks the beginning of a transaction. All procedures attempted between "Begin" and the next command (either "Rollback" or "Commit") are considered part of the transaction. Consider the following pseudo T-SQL command:

begin transaction 

insert into account (account,amount,debitcredit) values (100,100,'d') 
insert into account (account,amount,debitcredit) values (300,100,'c') 

if (@@ERROR > 0) 
rollback

else 
commit

In ADO+ (as in ADO), you can control transactions through the Connection object. In fact, when you use the ADOConnection, it uses the same underlying OLEDB transaction model. Therefore, if you were able to do transactions against your database with ADO, you can do them with ADO+, too. The sample code below uses the SQLConnection and SQLCommand to update a Customer record, and add an order. If either action fails, the records are rolled back.

**Important Note***
The DataSet object also has a commit model (AcceptChanges,RejectChanges) but it doesn't not affect the database. This commit model is for the cache of data in the DataSet alone.