Performing Transactions 

Transactions are groups of operations combined into logical units of work. They are used to control and maintain the consistency and integrity of each action in a transaction, despite errors that might occur in the system.

For example, in a banking application where funds are transferred from one account to another, one account is credited an amount in a database table, and another account is debited the same amount at the same time in another database table. Because computers can fail, it is possible to update a row in one table, but fail to update the row in the other table.

If your database supports transactions, you can group multiple database operations into a single transaction to prevent database inconsistency. If a failure occurs at one point in the transaction, all of the updates can be rolled back to their pre-transaction state. If no failures occur, the updates can be finalized by committing the transaction as complete.

Transactions in database servers usually must conform to the ACID properties--atomicity, consistency, isolation, and durability--in order to qualify as transactions. Most relational database systems, such as Microsoft SQL Server, intrinsically support transactions by providing locking, logging, and transaction management facilities for implicit transactions, which occur whenever a client application performs an update, insert or delete operation. Internally you can create explicit transactions using the SQL BEGIN TRANSACTION, COMMIT TRANSACTION, or ROLLBACK TRANSACTION statements.

In This Section

Performing a Transaction

Demonstrates how to use the Connection and Transaction objects to perform transactions against a data source.

Performing a Distributed Transaction

Describes how to perform distributed transactions in ADO.NET.

See Also