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

定義

データベースでトランザクションを開始します。Begins a transaction at the database.

オーバーロード

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

データベースでトランザクションを開始します。Begins a transaction at the database.

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

指定したデータベースでトランザクションを開始IsolationLevel値。Begins a transaction at the database with the specified IsolationLevel value.

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

データベースでトランザクションを開始します。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

戻り値

新しいトランザクションを表すオブジェクト。An object representing the new transaction.

例外

並列トランザクションはサポートされていません。Parallel transactions are not supported.

次の例では、作成、OracleConnectionOracleTransactionします。The following example creates an OracleConnection and an OracleTransaction. 使用する方法も示します、 BeginTransactionCommit、およびRollbackメソッド。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

注釈

トランザクションをロールバックまたはコミットは、する必要があります明示的に使用する、CommitまたはRollbackメソッド。To commit or roll back the transaction, you must explicitly use the Commit or Rollback methods.

.NET Framework Data Provider for Oracle トランザクションの管理モデルを正しく実行することを確認するには、データベースによって提供されるものなど、他のトランザクション管理モデルを使用しないでください。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.

注意

分離レベルを指定しない場合は、既定の分離レベルが使用されます。If you do not specify an isolation level, the default isolation level is used. 分離レベルを指定する、BeginTransactionメソッドを使用して、BeginTransactionオーバー ロードします。To specify an isolation level with the BeginTransaction method, use the BeginTransaction overload.

こちらもご覧ください

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

指定したデータベースでトランザクションを開始IsolationLevel値。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

パラメーター

il
IsolationLevel IsolationLevel IsolationLevel IsolationLevel

この接続のトランザクション分離レベル。The transaction isolation level for this connection.

戻り値

新しいトランザクションを表すオブジェクト。An object representing the new transaction.

例外

並列トランザクションはサポートされていません。Parallel transactions are not supported.

次の例では、作成、OracleConnectionOracleTransactionします。The following example creates an OracleConnection and an OracleTransaction. 使用する方法も示します、 BeginTransactionCommit、およびRollbackメソッド。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

注釈

トランザクションをロールバックまたはコミットは、する必要があります明示的に使用する、CommitまたはRollbackメソッド。To commit or roll back the transaction, you must explicitly use the Commit or Rollback methods.

.NET Framework Data Provider for Oracle トランザクションの管理モデルを正しく実行することを確認するには、データベースによって提供されるものなど、他のトランザクション管理モデルを使用しないでください。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.

こちらもご覧ください

適用対象