2011-02-25 8 views
0

우리는 데이터베이스 1에 전화를 걸고 웹 서비스에 호출 한 다음 데이터베이스 2에 호출하는 엔터프라이즈 응용 프로그램을 하나의 이벤트 순서로 모두 가지고 있습니다. 전체 처리를 트랜잭션으로 캡슐화하고 싶습니다. 이 시나리오에서 분산 트랜잭션을 구현하는 가장 좋은 방법은 무엇입니까?Asp.net 응용 프로그램의 분산 트랜잭션

환경 : SQL 2008, ASP.Net 3.5

답변

2

사용하십시오 TransactionScope 객체와 다른 연결 (각 데이터베이스에 대해 하나). 트랜잭션은 자동으로 분산 된 트랜잭션으로 전달됩니다.

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(); 
    } 
다음 MSDN 페이지의 예에서

관련 문제