31.1 Comments/Troubleshooting

A .NET transaction is created by calling the BeginTransaction( ) method on the Connection object. All subsequent operations associated with the transaction, such as committing or aborting the transaction, are performed using the Transaction object.

Transactions should be used only when required. Using transactions imposes a performance penalty due to the system overhead in managing the transaction. Transactions can also block work of other users in the system, which causes performance problems. For that reason, if transactions are required, the isolation level of the transactions should be carefully considered.

Because the Transaction is a connected class, each .NET data provider implements its own Transaction class, with a similar interface and function as other Transaction classes but in its own unique namespace. The Transaction class namespaces for several ADO.NET data providers are listed in Table 31-1.

Table 31-1. Provider-specific transaction classes


Data source


SQL Server


OLE DB provider


ODBC driver



The commonly used public properties of the Transaction class are listed in Table 31-2.

Table 31-2. Transaction properties




Gets the connection associated with the transaction.


Gets the isolation level for the transaction.

The commonly used public methods of the Transaction class are listed in Table 31-3.

Table 31-3. Transaction methods



Begin(  )

Starts a nested transaction (OLE DB only).

Commit(  )

Commits the transaction.

Rollback(  )

Rolls back a transaction from a pending state.

Save(  )

Creates a savepoint in the transaction that can be used to roll back a portion of the transaction (SQL Server only).

The Transaction class inherits from MarshalByRefObject and implements the IDbTransaction and IDisposable interfaces. Public static members of this class are safe for multithreaded operations; instance members aren't guaranteed thread-safe.

    Part I: ADO.NET Tutorial
    Part II: ADO.NET Core Classes
    Part III: API Quick Reference