0

データベース 1 への呼び出し、Web サービスへの呼び出し、データベース 2 への呼び出しをすべて 1 つのイベント シーケンスで行うエンタープライズ アプリケーションがあります。処理全体をトランザクションにカプセル化したいと考えています。このシナリオで分散トランザクションを実装する最良の方法は何ですか?

環境: SQL 2008、ASP.Net 3.5

4

1 に答える 1

2

TransactionScopeオブジェクトと異なる接続 (データベースごとに 1 つ) を使用します。トランザクションは自動的に分散トランザクションにエスカレートします。

MSDN ページの例から:

    using (TransactionScope scope = new TransactionScope())
    {
        using (SqlConnection connection1 = new SqlConnection(connectString1))
        {
            // Opening the connection automatically enlists it in the 
            // TransactionScope as a lightweight transaction.
            connection1.Open();

            using (SqlConnection connection2 = new SqlConnection(connectString2))
            {
                // The transaction is escalated to a full distributed
                // transaction when connection2 is opened.
                connection2.Open();
            }
        }

        scope.Complete();
    }
于 2011-02-25T08:47:50.383 に答える