OracleTransaction Class
Represents a transaction to be made at a database. This class cannot be inherited.
For a list of all members of this type, see OracleTransaction Members.
System.Object
System.MarshalByRefObject
System.Data.OracleClient.OracleTransaction
[Visual Basic] NotInheritable Public Class OracleTransaction Inherits MarshalByRefObject Implements IDbTransaction, IDisposable [C#] public sealed class OracleTransaction : MarshalByRefObject, IDbTransaction, IDisposable [C++] public __gc __sealed class OracleTransaction : public MarshalByRefObject, IDbTransaction, IDisposable [JScript] public class OracleTransaction extends MarshalByRefObject implements IDbTransaction, IDisposable
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The application creates an OracleTransaction object by calling BeginTransaction on the OracleConnection object. All subsequent operations associated with the transaction (for example, committing or aborting the transaction), are performed on the OracleTransaction object.
Example
[Visual Basic, C#, C++] The following example creates an OracleConnection and an OracleTransaction. It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.
[Visual Basic] Public Sub RunOracleTransaction(myConnString As String) Dim myConnection As New OracleConnection(myConnString) myConnection.Open() Dim myCommand As OracleCommand = myConnection.CreateCommand() Dim myTrans As OracleTransaction ' Start a local transaction myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted) ' Assign transaction object for a pending local transaction myCommand.Transaction = myTrans Try myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')" myCommand.ExecuteNonQuery() myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')" myCommand.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 myConnection.Close() End Try End Sub [C#] public void RunOracleTransaction(string myConnString) { OracleConnection myConnection = new OracleConnection(myConnString); myConnection.Open(); OracleCommand myCommand = myConnection.CreateCommand(); OracleTransaction myTrans; // Start a local transaction myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted); // Assign transaction object for a pending local transaction myCommand.Transaction = myTrans; try { myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"; myCommand.ExecuteNonQuery(); myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')"; myCommand.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 { myConnection.Close(); } } [C++] public: void RunOracleTransaction(String* myConnString) { OracleConnection* myConnection = new OracleConnection(myConnString); myConnection->Open(); OracleCommand* myCommand = myConnection->CreateCommand(); OracleTransaction* myTrans; // Start a local transaction myTrans = myConnection->BeginTransaction(IsolationLevel::ReadCommitted); // Assign transaction object for a pending local transaction myCommand->Transaction = myTrans; try { myCommand->CommandText = S"INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"; myCommand->ExecuteNonQuery(); myCommand->CommandText = S"INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')"; myCommand->ExecuteNonQuery(); myTrans->Commit(); Console::WriteLine(S"Both records are written to database."); } catch(Exception* e) { myTrans->Rollback(); Console::WriteLine(e); Console::WriteLine(S"Neither record was written to database."); } __finally { myConnection->Close(); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Data.OracleClient
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)
See Also
OracleTransaction Members | System.Data.OracleClient Namespace | OracleDataAdapter | OracleConnection