Επεξεργασία

Κοινή χρήση μέσω


OracleTransaction Class

Definition

Represents a transaction to be made in the database.

public ref class OracleTransaction sealed : MarshalByRefObject, IDisposable, System::Data::IDbTransaction
public ref class OracleTransaction sealed : System::Data::Common::DbTransaction
public sealed class OracleTransaction : MarshalByRefObject, IDisposable, System.Data.IDbTransaction
public sealed class OracleTransaction : System.Data.Common.DbTransaction
type OracleTransaction = class
    inherit MarshalByRefObject
    interface IDbTransaction
    interface IDisposable
type OracleTransaction = class
    inherit DbTransaction
Public NotInheritable Class OracleTransaction
Inherits MarshalByRefObject
Implements IDbTransaction, IDisposable
Public NotInheritable Class OracleTransaction
Inherits DbTransaction
Inheritance
OracleTransaction
Inheritance
Implements

Examples

The following example creates an OracleConnection and an OracleTransaction. It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.

public void RunOracleTransaction(string connectionString)
{
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        connection.Open();

        OracleCommand command = connection.CreateCommand();
        OracleTransaction transaction;

        // Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
        // Assign transaction object for a pending local transaction
        command.Transaction = transaction;

        try
        {
            command.CommandText =
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
            command.ExecuteNonQuery();
            command.CommandText =
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')";
            command.ExecuteNonQuery();
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception e)
        {
            transaction.Rollback();
            Console.WriteLine(e.ToString());
            Console.WriteLine("Neither record was written to database.");
        }
    }
}
Public Sub RunOracleTransaction(ByVal connectionString As String)
    Using connection As New OracleConnection(connectionString)
        connection.Open()

        Dim command As OracleCommand = connection.CreateCommand()
        Dim transaction As OracleTransaction

        ' Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)
        ' Assign transaction object for a pending local transaction
        command.Transaction = transaction

        Try
            command.CommandText = _
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"
            command.ExecuteNonQuery()
            command.CommandText = _
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')"
            command.ExecuteNonQuery()
            transaction.Commit()
            Console.WriteLine("Both records are written to database.")
        Catch e As Exception
            transaction.Rollback()
            Console.WriteLine(e.ToString())
            Console.WriteLine("Neither record was written to database.")
        End Try
    End Using
End Sub

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.

Properties

Connection

Specifies the OracleConnection object associated with the transaction.

DbConnection

When overridden in a derived class, gets the DbConnection object associated with the transaction.

(Inherited from DbTransaction)
IsolationLevel

Specifies the IsolationLevel for this transaction.

SupportsSavepoints

Gets a value that indicates whether this DbTransaction instance supports database savepoints. If false, the methods SaveAsync(String, CancellationToken), RollbackAsync(String, CancellationToken) and ReleaseAsync(String, CancellationToken) as well as their synchronous counterparts are expected to throw NotSupportedException.

(Inherited from DbTransaction)

Methods

Commit()

Commits the SQL database transaction.

CommitAsync(CancellationToken)

Asynchronously commits the database transaction.

(Inherited from DbTransaction)
CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases the resources used by this object.

Dispose()

Releases the unmanaged resources used by the DbTransaction.

(Inherited from DbTransaction)
Dispose(Boolean)

Releases the unmanaged resources used by the DbTransaction and optionally releases the managed resources.

(Inherited from DbTransaction)
DisposeAsync()

Asynchronously disposes the transaction object.

(Inherited from DbTransaction)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Release(String)

Destroys a savepoint previously defined in the current transaction. This allows the system to reclaim some resources before the transaction ends.

(Inherited from DbTransaction)
ReleaseAsync(String, CancellationToken)

Destroys a savepoint previously defined in the current transaction. This allows the system to reclaim some resources before the transaction ends.

(Inherited from DbTransaction)
Rollback()

Rolls back a transaction from a pending state.

Rollback(String)

Rolls back all commands that were executed after the specified savepoint was established.

(Inherited from DbTransaction)
RollbackAsync(CancellationToken)

Asynchronously rolls back a transaction from a pending state.

(Inherited from DbTransaction)
RollbackAsync(String, CancellationToken)

Rolls back all commands that were executed after the specified savepoint was established.

(Inherited from DbTransaction)
Save(String)

Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint.

(Inherited from DbTransaction)
SaveAsync(String, CancellationToken)

Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint.

(Inherited from DbTransaction)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IDbTransaction.Connection

Gets the DbConnection object associated with the transaction, or a null reference if the transaction is no longer valid.

(Inherited from DbTransaction)

Applies to

See also