DekGenius.com
[ Team LiB ] Previous Section Next Section

IDbTransaction disposable

System.Data (system.data.dll) interface

This class encapsulates a relational database transaction. You can start a transaction, provided you have an open connection, by calling the IDbConnection.BeginTransaction( ) method, which returns an IDbTransaction instance. You can enlist commands in a transaction by setting their IDbCommand.Transaction property to the appropriate IDbTransaction object. You end the transaction by calling the Commit( ) method to complete the transaction and accept all changes, or the Rollback( ) method to cancel all changes. Different providers have different ways to support nested transactions. A relational database provider defines a provider-specific transaction object that implements IDbTransaction , such as System.Data.SqlClient.SqlTransaction .

One important fact is that the IDbTransaction class represents a data provider transaction; it's analogous to executing the BEGIN TRANSACTION SQL statement in SQL Server (or a similar statement in other data sources). It has nothing in common with COM+ services.

When creating a transaction, be sure that you understand the isolation level it uses, which determines how other users can interact with the same data. The default transaction level (set by the IsolationLevel property) is IsolationLevel.ReadCommitted , which means that shared locks are held while the data is being read to avoid dirty reads, but the data can be changed before the end of the transaction, resulting in nonrepeatable reads or phantom data.

public interface IDbTransaction : IDisposable {
// Public Instance Properties
   public IDbConnection Connection{get; } 
   public IsolationLevel IsolationLevel{get; } 
// Public Instance Methods
   public void Commit(  );  
   public void Rollback(  );  
}

Implemented By

System.Data.OleDb.OleDbTransaction , System.Data.OracleClient.OracleTransaction , System.Data.SqlClient.SqlTransaction

Returned By

IDbCommand.Transaction , IDbConnection.BeginTransaction( )

Passed To

IDbCommand.Transaction

    [ Team LiB ] Previous Section Next Section