How does TransactionScope work?

后端 未结 2 752
长发绾君心
长发绾君心 2020-12-25 11:28

When Method1() instantiates a TransactionScope and calls Method2() that also instantiates a TransactionScope, how does .N

相关标签:
2条回答
  • 2020-12-25 11:56

    TransactionScope pretty much builds on top of COM - specifically over MSDTC.

    This coordinates transactions, and allows nesting of transactions.

    In short, when you first call TransactionScope, a transaction registers with MSDTC, as would all other calls to TransactionScope. MSDTC coordinates them all.

    0 讨论(0)
  • 2020-12-25 12:13

    Hope this helps:

    http://msdn.microsoft.com/en-us/magazine/cc300805.aspx

    For those unfamiliar with TransactionScope, it is part of the System.Transactions namespace new to the Microsoft® .NET Framework 2.0. System.Transactions provides a transactions framework fully integrated into the .NET Framework, including but not limited to ADO.NET. The Transaction and TransactionScope classes are two of the most important classes in this namespace. As the question alludes to, you can create a TransactionScope instance, and ADO.NET operations executed within the scope of that TransactionScope will be enlisted automatically (you can also access the current Transaction through the Transaction.Current static property):

    using(TransactionScope scope = new TransactionScope())
    {
        ... // all operations here part of a transaction
        scope.Complete();
    }
    
    0 讨论(0)
提交回复
热议问题