System.Data.SqlClient.SqlConnection.BeginTransaction Method

Starts a database transaction with the specified isolation level.

Syntax

public SqlTransaction BeginTransaction (System.Data.IsolationLevel iso)

Parameters

iso
The isolation level under which the transaction should run.

Returns

An object representing the new transaction.

Remarks

This command maps to the ssNoVersion implementation of BEGIN TRANSACTION.

You must explicitly commit or roll back the transaction using the SqlTransaction.Commit or SqlTransaction.Rollback method. To make sure that the dnprdnshort Data Provider for ssNoVersion transaction management model performs correctly, avoid using other transaction management models, such as the one provided by ssNoVersion.

Note:

After a transaction is committed or rolled back, the isolation level of the transaction persists for all subsequent commands that are in autocommit mode (the ssNoVersion default). This can produce unexpected results, such as an isolation level of REPEATABLE READ persisting and locking other users out of a row. To reset the isolation level to the default (READ COMMITTED), execute the tsql SET TRANSACTION ISOLATION LEVEL READ COMMITTED statement, or call SqlConnection.BeginTransaction followed immediately by SqlTransaction.Commit. For more information on ssNoVersion isolation levels, see "Isolation Levels in the Database Engine" in ssNoVersion Books Online.

For more information on ssNoVersion transactions, see "Explicit Transactions" and "Coding Efficient Transactions" in ssNoVersion Books Online.

Note:

When your query returns a large amount of data and calls BeginTransaction, a System.Data.SqlClient.SqlException is thrown because ssNoVersion does not allow parallel transactions when using MARS. To avoid this problem, always associate a transaction with the command, the connection, or both before any readers are open.

Requirements

Namespace: System.Data.SqlClient
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0