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

Class

Data source

System.Data.SqlClient.SqlTransaction

SQL Server

System.Data.OleDb.OleDbTransaction

OLE DB provider

Microsoft.Data.Odbc.OdbcTransaction

ODBC driver

System.Data.OracleClient.OracleTransaction

Oracle

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

Table 31-2. Transaction properties

Property

Description

Connection

Gets the connection associated with the transaction.

IsolationLevel

Gets the isolation level for the transaction.

The commonly ...

Get ADO.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.