'Declaration Public Class DB2Transaction Inherits Devart.Common.DbTransactionBase Implements System.Data.IDbTransaction, System.IDisposable
public class DB2Transaction : Devart.Common.DbTransactionBase, System.Data.IDbTransaction, System.IDisposable
'Declaration Public Class DB2Transaction Inherits Devart.Common.DbTransactionBase Implements System.Data.IDbTransaction, System.IDisposable
public class DB2Transaction : Devart.Common.DbTransactionBase, System.Data.IDbTransaction, System.IDisposable
The application creates a DB2Transaction object by calling DB2Connection.BeginTransaction on the DB2Connection object. All subsequent operations associated with the transaction (for example, committing or aborting the transaction), are performed on the DB2Transaction object.
The correlation between DB2Connection and DB2Transaction is always 1:1.
public static void RunDB2Transaction(string myConnString) { using (DB2Connection db2Connection = new DB2Connection(myConnString)) { db2Connection.Open(); // Start a local transaction DB2Transaction myTrans = db2Connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); DB2Command db2Command = db2Connection.CreateCommand(); try { db2Command.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(52, 'DEVELOPMENT')"; db2Command.ExecuteNonQuery(); db2Command.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(62, 'PRODUCTION')"; db2Command.ExecuteNonQuery(); myTrans.Commit(); Console.WriteLine("Both records are written to database."); } catch (Exception e) { myTrans.Rollback(); Console.WriteLine(e.ToString()); Console.WriteLine("Neither record was written to database."); } finally { db2Command.Dispose(); myTrans.Dispose(); } } }
Public Shared Sub RunDB2Transaction(myConnString As String) Using db2Connection As New DB2Connection(myConnString) db2Connection.Open() ' Start a local transaction Dim myTrans As DB2Transaction = db2Connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted) Dim db2Command As DB2Command = db2Connection.CreateCommand() Try db2Command.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(52, 'DEVELOPMENT')" db2Command.ExecuteNonQuery() db2Command.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(62, 'PRODUCTION')" db2Command.ExecuteNonQuery() myTrans.Commit() Console.WriteLine("Both records are written to database.") Catch e As Exception myTrans.Rollback() Console.WriteLine(e.ToString()) Console.WriteLine("Neither record was written to database.") Finally db2Command.Dispose() myTrans.Dispose() End Try End Using End Sub
System.Object
System.MarshalByRefObject
System.Data.Common.DbTransaction
Devart.Common.DbTransactionBase
Devart.Data.DB2.DB2Transaction
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2