Do Transaction scope uses MSDTC when running on one database

Itay Hay 6 Reputation points
2023-03-22T11:30:20.01+00:00

Hey,

As part of an OutBox pattern architecture - where there is a requirement to atomically update the database and publish messages/events.

so the problem is :

How to reliably/atomically update the database and send messages/events?

To answer this problem I Plan on using Transaction scope to manage the transaction.

My question is :

If all transactions are ran against a single database -

do transaction scope still uses MSDTC(Distributed Transaction Coordinator) when running on a single database?

My concern is performance issues that might be caused due to this kind of transactions.

Many thanks

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Oury Ba-MSFT 20,931 Reputation points Microsoft Employee Moderator
    2023-03-24T17:15:17.8333333+00:00

    @Itay Hay

    TransactionScope (and System.Transactions) use lightweight promotabble transactions. So you can avoid MSDTC unless your code requires it. EG if two seperate SqlConnection objects are open at the same time and enlist in the same transaction, then it will trigger promotion. But if the SqlConnections run one after the other, then they will share the same underlying connection and lightweight SQL Server transaction. See: System.Transactions Integration with SQL Server - ADO.NET | Microsoft Learn

    Regards,

    Oury

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.