asp.net.ph

OleDbConnection.BeginTransaction Method ( IsolationLevel )

System.Data.OleDbClient Namespace   OleDbConnection Class


Begins a database transaction with the current IsolationLevel value.

[ VB ]
Overloads Public Function BeginTransaction ( _
   ByVal iso As IsolationLevel _
) As OleDbTransaction

[ C# ]
public OleDbTransaction BeginTransaction (
   IsolationLevel iso
);

[ C++ ]
public: OleDbTransaction BeginTransaction (
   IsolationLevel* iso
);

[ JScript ]
public function BeginTransaction (
   iso : IsolationLevel
) : OleDbTransaction

Parameters

iso
The isolation level under which the transaction should run.

Return Value

An object representing the new transaction.

Exceptions


Exception Type Condition
InvalidOperationException Occurs when Parallel transactions are not supported.

Remarks

You must explicity commit or roll back the transaction using the Commit or Rollback method. To ensure that the OLE DB .NET Data Provider transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.

Example

The following example initializes an OleDbConnection, opens it, begins a transaction, commits the transaction, then closes the connection.

void RunOleDbTransaction ( string connString ) {
   OleDbConnection myConn = new OleDbConnection ( connString );
   myConn.Open ( );

   OleDbCommand myCommand = new OleDbCommand ( );
   OleDbTransaction myTrans;

   // start a local transaction
   myTrans = myConn.BeginTransaction ( IsolationLevel.ReadCommitted );
   // assign transaction object for a pending local transaction
   myCommand.Transaction = myTrans;

   try {
      myCommand.CommandText = "Insert into Region (
         RegionID, RegionDescription ) VALUES ( 100, 'Description' ) ";
      myCommand.ExecuteNonQuery ( );

      myTrans.Commit ( );
      Response.Write ( "One record written to database." );
   } catch ( Exception e ) {
      myTrans.Rollback ( );
      Response.Write ( e.ToIsolationLevel ( ) );
      Response.Write ( "No record written to database." );
   } finally {
      myConn.Close ( );
   }
}
  C# VB

See Also

OleDbConnection Members   OleDbConnection.BeginTransaction Overload List   Commit   Save   Rollback Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph