Does TransactionScope Need DTC Service on?

后端 未结 2 1119
無奈伤痛
無奈伤痛 2021-02-05 23:21

From what I\'m reading, in order to use TransactionScope in .NET, you need the Distributed Transaction Coordinator service in Windows to be running. I have that service

相关标签:
2条回答
  • 2021-02-06 00:03

    MSDTC comes into the play only if you have more than one transaction with different connections

    SO, the answer is:

    It depends!

    • If you use 1 TranScope per 1 connection - then NO
    • If you use 1 TranScope per more than 1 connection - then YES
    • If you created TransactionScope object which requires Distributed transaction - then YES
    0 讨论(0)
  • 2021-02-06 00:22

    More modern versions of windows have a mini DTC version in kernel. It is not distributed but uses the same API - but it can only handle one ressource per transaction scope.

    TransactionScope uses that at a start, then "promotes" the transaction to the real DTC the moment a second resource is added (resource in your case is a database connection). So, as long as your use case is ismple, you avoid the (high) overhead of the DISTRIBUTED part of DTC and can work without the service running.

    More information about the Kernel Transaction Managger can be found at http://en.wikipedia.org/wiki/Kernel_Transaction_Manager

    MS added it also because NTFS got transactional and it needed to make sure a DTC is aavailable.

    http://www.codeguru.com/cpp/article.php/c18309/

    0 讨论(0)
提交回复
热议问题