OracleConnection.BeginTransaction OracleConnection.BeginTransaction OracleConnection.BeginTransaction OracleConnection.BeginTransaction Method

Definizione

Inizia una transazione a livello di database.Begins a transaction at the database.

Overload

BeginTransaction() BeginTransaction() BeginTransaction() BeginTransaction()

Inizia una transazione a livello di database.Begins a transaction at the database.

BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel)

Inizia una transazione a livello di database con l'oggetto specificato IsolationLevel valore.Begins a transaction at the database with the specified IsolationLevel value.

BeginTransaction() BeginTransaction() BeginTransaction() BeginTransaction()

Inizia una transazione a livello di database.Begins a transaction at the database.

public:
 System::Data::OracleClient::OracleTransaction ^ BeginTransaction();
public System.Data.OracleClient.OracleTransaction BeginTransaction ();
override this.BeginTransaction : unit -> System.Data.OracleClient.OracleTransaction
Public Function BeginTransaction () As OracleTransaction

Restituisce

Oggetto che rappresenta la nuova transazione.An object representing the new transaction.

Eccezioni

Le transazioni parallele non sono supportate.Parallel transactions are not supported.

Esempi

L'esempio seguente crea un OracleConnection e un OracleTransaction.The following example creates an OracleConnection and an OracleTransaction. Viene inoltre illustrato come usare il BeginTransaction, Commit, e Rollback metodi.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

Commenti

Per eseguire il commit o rollback della transazione, è necessario usare in modo esplicito il Commit o Rollback metodi.To commit or roll back the transaction, you must explicitly use the Commit or Rollback methods.

Per assicurarsi che il Provider di dati .NET Framework per il modello di gestione delle transazioni Oracle venga eseguito correttamente, evitare di usare altri modelli di gestione delle transazioni, come quelli forniti dai database.To ensure that the .NET Framework Data Provider for Oracle transaction management model performs correctly, avoid using other transaction management models, such as those provided by the database.

Nota

Se non si specifica un livello di isolamento, viene utilizzato il livello di isolamento predefinito.If you do not specify an isolation level, the default isolation level is used. Per specificare un livello di isolamento con la BeginTransaction metodo, usare il BeginTransaction rapporto di overload.To specify an isolation level with the BeginTransaction method, use the BeginTransaction overload.

Vedi anche

BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel)

Inizia una transazione a livello di database con l'oggetto specificato IsolationLevel valore.Begins a transaction at the database with the specified IsolationLevel value.

public:
 System::Data::OracleClient::OracleTransaction ^ BeginTransaction(System::Data::IsolationLevel il);
public System.Data.OracleClient.OracleTransaction BeginTransaction (System.Data.IsolationLevel il);
override this.BeginTransaction : System.Data.IsolationLevel -> System.Data.OracleClient.OracleTransaction
Public Function BeginTransaction (il As IsolationLevel) As OracleTransaction

Parametri

il
IsolationLevel IsolationLevel IsolationLevel IsolationLevel

Livello di isolamento della transazione per questa connessione.The transaction isolation level for this connection.

Restituisce

Oggetto che rappresenta la nuova transazione.An object representing the new transaction.

Eccezioni

Le transazioni parallele non sono supportate.Parallel transactions are not supported.

Esempi

L'esempio seguente crea un OracleConnection e un OracleTransaction.The following example creates an OracleConnection and an OracleTransaction. Viene inoltre illustrato come usare il BeginTransaction, Commit, e Rollback metodi.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

Commenti

Per eseguire il commit o rollback della transazione, è necessario usare in modo esplicito il Commit o Rollback metodi.To commit or roll back the transaction, you must explicitly use the Commit or Rollback methods.

Per assicurarsi che il Provider di dati .NET Framework per il modello di gestione delle transazioni Oracle venga eseguito correttamente, evitare di usare altri modelli di gestione delle transazioni, come quelli forniti dai database.To ensure that the .NET Framework Data Provider for Oracle transaction management model performs correctly, avoid using other transaction management models, such as those provided by the database.

Vedi anche

Si applica a