次の方法で共有


OdbcTransaction クラス

定義

データ ソースで実行される SQL トランザクションを表します。 このクラスは継承できません。

public ref class OdbcTransaction sealed : System::Data::Common::DbTransaction
public ref class OdbcTransaction sealed : MarshalByRefObject, IDisposable, System::Data::IDbTransaction
public sealed class OdbcTransaction : System.Data.Common.DbTransaction
public sealed class OdbcTransaction : MarshalByRefObject, IDisposable, System.Data.IDbTransaction
type OdbcTransaction = class
    inherit DbTransaction
type OdbcTransaction = class
    inherit MarshalByRefObject
    interface IDbTransaction
    interface IDisposable
Public NotInheritable Class OdbcTransaction
Inherits DbTransaction
Public NotInheritable Class OdbcTransaction
Inherits MarshalByRefObject
Implements IDbTransaction, IDisposable
継承
継承
OdbcTransaction
実装

次の例では、OdbcConnectionOdbcTransactionを作成します。 また、BeginTransactionCommit、および Rollback メソッドの使用方法についても説明します。

public static void ExecuteTransaction(string connectionString)
{
    using (OdbcConnection connection =
               new OdbcConnection(connectionString))
    {
        OdbcCommand command = new OdbcCommand();
        OdbcTransaction transaction = null;

        // Set the Connection to the new OdbcConnection.
        command.Connection = connection;

        // Open the connection and execute the transaction.
        try
        {
            connection.Open();

            // Start a local transaction
            transaction = connection.BeginTransaction();

            // Assign transaction object for a pending local transaction.
            command.Connection = connection;
            command.Transaction = transaction;

            // Execute the commands.
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
            command.ExecuteNonQuery();
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
            command.ExecuteNonQuery();

            // Commit the transaction.
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            try
            {
                // Attempt to roll back the transaction.
                transaction.Rollback();
            }
            catch
            {
                // Do nothing here; transaction is not active.
            }
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
Public Sub ExecuteTransaction(ByVal connectionString As String)

    Using connection As New OdbcConnection(connectionString)
        Dim command As New OdbcCommand()
        Dim transaction As OdbcTransaction

        ' Set the Connection to the new OdbcConnection.
        command.Connection = connection

        ' Open the connection and execute the transaction.
        Try
            connection.Open()

            ' Start a local transaction.
            transaction = connection.BeginTransaction()

            ' Assign transaction object for a pending local transaction.
            command.Connection = connection
            command.Transaction = transaction

            ' Execute the commands.
            command.CommandText = _
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
            command.ExecuteNonQuery()
            command.CommandText = _
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"
            command.ExecuteNonQuery()

            ' Commit the transaction.
            transaction.Commit()
            Console.WriteLine("Both records are written to database.")

        Catch ex As Exception
            Console.WriteLine(ex.Message)
            ' Try to rollback the transaction
            Try
                transaction.Rollback()

            Catch
                ' Do nothing here; transaction is not active.
            End Try
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using
End Sub

注釈

アプリケーションは、OdbcConnection オブジェクトの BeginTransaction を呼び出して、OdbcTransaction オブジェクトを作成します。 トランザクションに関連付けられている後続のすべての操作 (トランザクションのコミットや中止など) は、OdbcTransaction オブジェクトに対して実行されます。

プロパティ

Connection

トランザクションに関連付けられている OdbcConnection オブジェクトを取得するか、トランザクションが無効になった場合に null します。

DbConnection

派生クラスでオーバーライドされると、トランザクションに関連付けられている DbConnection オブジェクトを取得します。

(継承元 DbTransaction)
IsolationLevel

このトランザクションの IsolationLevel を指定します。

SupportsSavepoints

この DbTransaction インスタンスがデータベース セーブポイントをサポートしているかどうかを示す値を取得します。 false場合、メソッド SaveAsync(String, CancellationToken)RollbackAsync(String, CancellationToken)、および ReleaseAsync(String, CancellationToken)、およびそれらの同期対応するメソッドは、NotSupportedExceptionをスローすることが期待されます。

(継承元 DbTransaction)

メソッド

Commit()

データベース トランザクションをコミットします。

CommitAsync(CancellationToken)

データベース トランザクションを非同期的にコミットします。

(継承元 DbTransaction)
CreateObjRef(Type)

リモート オブジェクトとの通信に使用されるプロキシの生成に必要なすべての関連情報を含むオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()

DbTransactionによって使用されるアンマネージ リソースを解放します。

(継承元 DbTransaction)
Dispose(Boolean)

DbTransaction によって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。

(継承元 DbTransaction)
DisposeAsync()

トランザクション オブジェクトを非同期的にディプスします。

(継承元 DbTransaction)
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
Release(String)

現在のトランザクションで以前に定義されたセーブポイントを破棄します。 これにより、システムはトランザクションが終了する前に一部のリソースを再利用できます。

(継承元 DbTransaction)
ReleaseAsync(String, CancellationToken)

現在のトランザクションで以前に定義されたセーブポイントを破棄します。 これにより、システムはトランザクションが終了する前に一部のリソースを再利用できます。

(継承元 DbTransaction)
Rollback()

保留中の状態からトランザクションをロールバックします。

Rollback(String)

指定したセーブポイントが確立された後に実行されたすべてのコマンドをロールバックします。

(継承元 DbTransaction)
RollbackAsync(CancellationToken)

保留中の状態からトランザクションを非同期的にロールバックします。

(継承元 DbTransaction)
RollbackAsync(String, CancellationToken)

指定したセーブポイントが確立された後に実行されたすべてのコマンドをロールバックします。

(継承元 DbTransaction)
Save(String)

トランザクションにセーブポイントを作成します。 これにより、セーブポイントが確立された後に実行されるすべてのコマンドをロールバックし、トランザクション状態をセーブポイントの時点の状態に復元できます。

(継承元 DbTransaction)
SaveAsync(String, CancellationToken)

トランザクションにセーブポイントを作成します。 これにより、セーブポイントが確立された後に実行されるすべてのコマンドをロールバックし、トランザクション状態をセーブポイントの時点の状態に復元できます。

(継承元 DbTransaction)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

IDbTransaction.Connection

トランザクションに関連付けられている DbConnection オブジェクトを取得します。トランザクションが無効になった場合は null 参照を取得します。

(継承元 DbTransaction)
IDisposable.Dispose()

この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。

OdbcTransaction クラスの現在のインスタンスによって使用されているリソースを解放します。

拡張メソッド

ConfigureAwait(IAsyncDisposable, Boolean)

非同期破棄から返されるタスクの待機を実行する方法を構成します。

適用対象

こちらもご覧ください