LoginSignup
4
4

More than 5 years have passed since last update.

分散トランザクションの実装方法

Posted at

1.プロジェクトに参照設定の追加

Visual Studio のソリューションエクスプローラー上で、右クリックで参照の追加を選択。

addref.png

タブ .NET より System.Transactions を選択する。

2.使用するクラスで Using を追加

smaple.cs

using System.Transactions;

3 分散トランザクションのコード追加

分散トランザクションは、TramsactoionScope 範囲内がトランザクションとなり、Complete() メソッド呼出し後に、スコープを抜けた時に確定する。途中で、例外などで Complete() が呼出しされなかった場合は、ロールバックとなる。

sample.cs

public void transFunction() 
{

  using (TransactionScope ts = new TransactionScope())
  {
     /**
      * ここで複数のデータベースに対する処理を行う。
      */



     // トランザクション確定
     ts.Complete();
  }


}
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4