문제

Please check the below code sample, I want A type process and B type process to be done both or none of them. Does below code success?

    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 30, 0)))
        {  

con.Open();
//do A type process
con.Close();

con.Open();
//do B type process
con.Close();


    scope.Complete();
        }

P.S: (Please don't suggest to use 1 con, the reason is that I use the 3 tier architecture at this link (http://geekswithblogs.net/edison/archive/2009/04/05/a-simple-3-tier-layers-application-in-asp.net.aspx), and A-B type processes are called with a function (genericdata class) which opens and closes it's connection automatically.) So the above code is the interpretation of my actual code.

도움이 되었습니까?

해결책

Using DTC, it will act like a layer between your DB layer and database. Which means any changes made to db will not be applied till you call .Complete(). It really doesn't matter which connection you use and how many database involved in transaction.

make sure you call .Complete() and end of transaction. Or even you can have nested transaction scope

Scope1 Scope2 Scope3

in above , whenever Scope1.Complete is called , data will be moved to database even though child scopes calls Complete

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top