IDbTransactionとは? わかりやすく解説

IDbTransaction インターフェイス

データ ソース実行するトランザクション示しますリレーショナル データベースアクセスする .NET Framework データ プロバイダによって実装されます

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Interface IDbTransaction
    Inherits IDisposable
Dim instance As IDbTransaction
public interface IDbTransaction : IDisposable
public interface IDbTransaction extends IDisposable
public interface IDbTransaction extends IDisposable
解説解説

IDbTransaction インターフェイスによって、継承クラスデータ ソース実行するトランザクションを示す Transaction クラス実装できますTransaction クラス詳細については、「トランザクション実行」を参照してください.NET Framework データ プロバイダ実装の詳細については、「Implementing a .NET Framework Data Provider」を参照してください

アプリケーションでは IDbTransaction インターフェイスインスタンス直接作成されず、IDbTransaction継承するクラスインスタンス作成されます。

IDbTransaction継承するクラスは、継承されメンバ実装する必要があり、通常プロバイダ固有の機能追加する追加メンバ定義する必要があります。たとえば、IDbTransaction インターフェイスCommit メソッド定義します次に、OleDbTransaction クラスがこのプロパティ継承しBegin メソッド定義します

実装時の注意 .NET Framework データ プロバイダ間に一貫性持たせるために、継承クラスには Prv Transaction という形式の名前を付けてくださいPrv は、各 .NET Framework データ プロバイダ名前空間内のすべてのクラスに付けられるプリフィックスです。たとえば、SqlSystem.Data.SqlClient 名前空間内の SqlTransaction クラスプリフィックスです。

使用例使用例

派生クラス SqlConnection および SqlTransactionインスタンス作成する例を次に示します。BeginTransaction、CommitRollback の各メソッド使い方示します

Private Sub ExecuteSqlTransaction(ByVal
 connectionString As String)
    Using connection As New SqlConnection(connectionString)
        connection.Open()

        Dim command As SqlCommand = connection.CreateCommand()
        Dim transaction As SqlTransaction

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

        ' Must assign both transaction object and connection
        ' to Command object for a pending local transaction.
        command.Connection = connection
        command.Transaction = transaction

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

            command.ExecuteNonQuery()

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

        Catch ex As Exception
            Console.WriteLine("Commit Exception Type: {0}",
 ex.GetType())
            Console.WriteLine("  Message: {0}", ex.Message)

            ' Attempt to roll back the transaction.
            Try
                transaction.Rollback()

            Catch ex2 As Exception
                ' This catch block will handle any errors that may have
 occurred
                ' on the server that would cause the rollback to fail,
 such as
                ' a closed connection.
                Console.WriteLine("Rollback Exception Type: {0}",
 ex2.GetType())
                Console.WriteLine("  Message: {0}",
 ex2.Message)
            End Try
        End Try
    End Using
End Sub
private static void ExecuteSqlTransaction(string
 connectionString)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();

        SqlCommand command = connection.CreateCommand();
        SqlTransaction transaction;

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

        // Must assign both transaction object and connection
        // to Command object for a pending local transaction
        command.Connection = connection;
        command.Transaction = transaction;

        try
        {
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (100,
 'Description')";
            command.ExecuteNonQuery();
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (101,
 'Description')";
            command.ExecuteNonQuery();

            // Attempt to commit the transaction.
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
            Console.WriteLine("  Message: {0}", ex.Message);

            // Attempt to roll back the transaction.
            try
            {
                transaction.Rollback();
            }
            catch (Exception ex2)
            {
                // This catch block will handle any errors that may
 have occurred
                // on the server that would cause the rollback to fail,
 such as
                // a closed connection.
                Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                Console.WriteLine("  Message: {0}", ex2.Message);
            }
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IDbTransaction プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ IsolationLevel このトランザクションの IsolationLevel を指定します
参照参照

関連項目

IDbTransaction インターフェイス
System.Data 名前空間

IDbTransaction メソッド


IDbTransaction メンバ



このページでは「.NET Framework クラス ライブラリ リファレンス」からIDbTransactionを検索した結果を表示しています。
Weblioに収録されているすべての辞書からIDbTransactionを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からIDbTransaction を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IDbTransaction」の関連用語

IDbTransactionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IDbTransactionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS