CommittableTransaction イベント
CommittableTransaction クラス
アセンブリ: System.Transactions (system.transactions.dll 内)

<SerializableAttribute> _ Public NotInheritable Class CommittableTransaction Inherits Transaction Implements IAsyncResult
[SerializableAttribute] public sealed class CommittableTransaction : Transaction, IAsyncResult
[SerializableAttribute] public ref class CommittableTransaction sealed : public Transaction, IAsyncResult
/** @attribute SerializableAttribute() */ public final class CommittableTransaction extends Transaction implements IAsyncResult
SerializableAttribute public final class CommittableTransaction extends Transaction implements IAsyncResult

CommittableTransaction クラスは、TransactionScope クラスを暗黙的に使用せずに、アプリケーションでトランザクションを使用する明示的な方法を提供します。TransactionScope クラスとは異なり、アプリケーションの作成者はトランザクションをコミットまたは中止するために、特に Commit メソッドと Rollback メソッドを呼び出す必要があります。ただし、トランザクションをコミットできるのは、そのトランザクションの作成者だけです。したがって、Clone メソッドを介して取得したコミット可能なトランザクションのコピーについてはコミットできません。
![]() |
---|
TransactionScope クラスを使用して暗黙のトランザクションを作成し、アンビエント トランザクション コンテキストを自動的に管理することをお勧めします。複数の関数呼び出しまたは複数のスレッド呼び出しで同じトランザクションを使用する必要のあるアプリケーション向けに、TransactionScope クラスおよび DependentTransaction クラスを使用する必要もあります。このモデルの詳細については、「トランザクション スコープを使用した暗黙的なトランザクションの実装」を参照してください。 |
CommittableTransaction を作成しても、アンビエント トランザクション (コードが実行されるトランザクション) が自動的に設定されるわけではありません。アンビエント トランザクションを取得または設定するには、グローバル オブジェクトである Transaction の静的な Current プロパティを呼び出します。アンビエント トランザクションの詳細については、「トランザクション スコープを使用した暗黙的なトランザクションの実装」で、TransactionScopeOption を使用したトランザクション フローの管理についての説明を参照してください。アンビエント トランザクションが設定されていない場合、そのトランザクションにはリソース マネージャに対するどのような操作も含まれません。リソース マネージャを正しいトランザクション コンテキストに基づいて確実に動作させるには、アンビエント トランザクションを明示的に設定およびリセットする必要があります。
CommittableTransaction がコミットされるまで、トランザクションに関連するすべてのリソースは引き続きロックされます。
CommittableTransaction オブジェクトは再利用できません。このオブジェクトはコミットまたはロールバックされると、トランザクションで使用したり、現在のアンビエント トランザクション コンテキストとして設定したりすることはできません。


System.Transactions.Transaction
System.Transactions.CommittableTransaction


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CommittableTransaction コンストラクタ ()
アセンブリ: System.Transactions (system.transactions.dll 内)


例外の種類 | 条件 |
---|---|
PlatformNotSupportedException | Windows 98、Windows 98 Second Edition、または Windows Millennium Edition でトランザクションを作成しようとしました。 |

CommittableTransaction の新しいインスタンスを作成してコミットする例を次に示します。
tx = New CommittableTransaction Dim myConnection As New SqlConnection("server=(local)\SQLExpress;Integrated Security=SSPI;database=northwind") Dim myCommand As New SqlCommand() 'Open the SQL connection myConnection.Open() 'Give the transaction to SQL to enlist with myConnection.EnlistTransaction(tx) myCommand.Connection = myConnection 'Restore database to near it's original condition so sample will work correctly. myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)" myCommand.ExecuteNonQuery() 'Insert the first record. myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')" myCommand.ExecuteNonQuery() 'Insert the second record. myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')" myCommand.ExecuteNonQuery() 'Commit or rollback the transaction Dim c As ConsoleKeyInfo While (True) Console.Write("Commit or Rollback? [C|R] ") c = Console.ReadKey() Console.WriteLine() If (c.KeyChar = "C") Or (c.KeyChar = "c") Then tx.Commit() Exit While ElseIf ((c.KeyChar = "R") Or (c.KeyChar = "r")) Then tx.Rollback() Exit While End If End While myConnection.Close() tx = Nothing
//Create a committable transaction tx = new CommittableTransaction(); SqlConnection myConnection = new SqlConnection("server=(local)\\SQLExpress;Integrated Security=SSPI;database=northwind"); SqlCommand myCommand = new SqlCommand(); //Open the SQL connection myConnection.Open(); //Give the transaction to SQL to enlist with myConnection.EnlistTransaction(tx); myCommand.Connection = myConnection; // Restore database to near it's original condition so sample will work correctly. myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)"; myCommand.ExecuteNonQuery(); // Insert the first record. myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')"; myCommand.ExecuteNonQuery(); // Insert the second record. myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')"; myCommand.ExecuteNonQuery(); // Commit or rollback the transaction while (true) { Console.Write("Commit or Rollback? [C|R] "); ConsoleKeyInfo c = Console.ReadKey(); Console.WriteLine(); if ((c.KeyChar == 'C') || (c.KeyChar == 'c')) { tx.Commit(); break; } else if ((c.KeyChar == 'R') || (c.KeyChar == 'r')) { tx.Rollback(); break; } } myConnection.Close(); tx = null;

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CommittableTransaction コンストラクタ (TimeSpan)
アセンブリ: System.Transactions (system.transactions.dll 内)


例外の種類 | 条件 |
---|---|
PlatformNotSupportedException | Windows 98、Windows 98 Second Edition、または Windows Millennium Edition でトランザクションを作成しようとしました。 |

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CommittableTransaction コンストラクタ (TransactionOptions)
アセンブリ: System.Transactions (system.transactions.dll 内)


例外の種類 | 条件 |
---|---|
PlatformNotSupportedException | Windows 98、Windows 98 Second Edition、または Windows Millennium Edition でトランザクションを作成しようとしました。 |
ArgumentException |


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CommittableTransaction コンストラクタ

名前 | 説明 |
---|---|
CommittableTransaction () | CommittableTransaction クラスの新しいインスタンスを初期化します。 |
CommittableTransaction (TimeSpan) | 指定した timeout 値を使用して、CommittableTransaction クラスの新しいインスタンスを初期化します。 |
CommittableTransaction (TransactionOptions) | 指定したトランザクション オプションを使用して、CommittableTransaction クラスの新しいインスタンスを初期化します。 |

CommittableTransaction プロパティ

名前 | 説明 | |
---|---|---|
![]() | Current | アンビエント トランザクションを取得または設定します。 ( Transaction から継承されます。) |
![]() | IsolationLevel | トランザクションの分離レベルを取得します。 ( Transaction から継承されます。) |
![]() | TransactionInformation | トランザクションの追加情報を取得します。 ( Transaction から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.IAsyncResult.AsyncState | BeginCommit メソッド呼び出しの最後のパラメータに指定されたオブジェクトを取得します。 |
![]() | System.IAsyncResult.AsyncWaitHandle | 非同期操作が完了するまで待機するために使用する WaitHandle を取得します。 |
![]() | System.IAsyncResult.CompletedSynchronously | 非同期のコミット操作が同期的に完了したかどうかを示す値を取得します。 |
![]() | System.IAsyncResult.IsCompleted | 非同期のコミット操作が完了したかどうかを示す値を取得します。 |

CommittableTransaction メソッド


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

CommittableTransaction メンバ
CommittableTransaction データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Current | アンビエント トランザクションを取得または設定します。(Transaction から継承されます。) |
![]() | IsolationLevel | トランザクションの分離レベルを取得します。(Transaction から継承されます。) |
![]() | TransactionInformation | トランザクションの追加情報を取得します。(Transaction から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | System.IAsyncResult.AsyncState | BeginCommit メソッド呼び出しの最後のパラメータに指定されたオブジェクトを取得します。 |
![]() | System.IAsyncResult.AsyncWaitHandle | 非同期操作が完了するまで待機するために使用する WaitHandle を取得します。 |
![]() | System.IAsyncResult.CompletedSynchronously | 非同期のコミット操作が同期的に完了したかどうかを示す値を取得します。 |
![]() | System.IAsyncResult.IsCompleted | 非同期のコミット操作が完了したかどうかを示す値を取得します。 |

- CommittableTransactionのページへのリンク