ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples


Transaction Processing in ADO.NET
Previous Home Next

ADO.NET supports transactions through the Transaction object, which is created against an open connection. Commands that are executed against the connection while the transaction is pending must be enrolled in the transaction by assigning a reference to the Transaction object to their Transaction property. Commands cannot be executed against the Connection outside the transaction while it is pending. If the transaction is committed, all of the commands that form a part of that transaction will be permanently written to the data source. If the transaction is rolled back, all of the commands will be discarded at the data source.

Creating Transactions

The Transaction object is implemented as part of the data provider. There is a version for each of the intrinsic data providers: OleDbTransaction in the System.Data. OleDb namespace and SqlTransaction in the System.Data.SqlClient namespace.The SqlTransaction object is implemented using Microsoft SQL Server transactions—creating a SqlTransaction maps directly to the BeginTransaction statement. The OleDbTransaction is implemented within OLE DB. Transactions are created by calling the BeginTransaction method of the Connection object, which returns a reference to a Transaction object. BeginTransaction is overloaded, allowing an IsolationLevel.The Connection must be valid and open when BeginTransaction is called.

Connection BeginTransaction Methods

    BeginTransaction(): Begins a transaction

    BeginTransaction(IsolationLevel): Begins a transaction at the specified Isolation Level

    BeginTransaction (TransactionName): transaction with the name specified in the Transaction Name string.

    BeginTransaction (IsolationLevel, TransactionName): Begins a transaction at the specified Isolation Level with the name specified in the Transaction Name string

Isolation Levels

    Chaos: Pending changes from more highly ranked transactions can not be over written

    ReadCommitted: Shared locks are held while the data is being read, but data can be changed before the endof the transaction

    ReadUncommitted: No shared locks are issued and no exclusive locks are honored

    RepeatableRead: Exclusive locks are placed on all data used in the query.

    Serializable: A rangelock is placed on the DataSet

    Unspecified: An existing isolation level cannot be determined

Previous Home Next