none
EF + dtc RRS feed

  • Question

  • Hi all,

    when I use EF in my c# Winform projects, is it correct to also launch the Windows service called "Distributed Transaction Coordinator"?
    Or can I leave it off?

    thanks
    d.

    Tuesday, May 19, 2020 4:58 PM

Answers

  • You only need to turn on DTC if your queries are going to use transactions (e.g. TransactionScope) across database (or even non-database) resources at the same time. The purpose of DTC is to coordinate the update of the resources across potentially different machines. In the vast majority of cases you do not need DTC and in fact it'll slow things down.

    In my experience if DTC is not running then when you try to do a distributed update in a transaction then you'll get an error letting you know DTC is needed. If you never see that error then you don't need it. However I've seen a few cases where some connection string settings might imply the need for DTC as well even if it is not used.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by duppino Thursday, May 21, 2020 7:25 AM
    Wednesday, May 20, 2020 1:44 PM
    Moderator
  • DTC would be enabled on a Web server machine and  a server machine  that was hosting MS SQL Server as an example. Any ASP.NET Web solution that used a transaction scope on the Web server would participate in a distributed transaction scope across the two machines the server hosting IIS with the ASP.NET Web solution and the server hosting MS SQL Server. The two machines would have DTC enabled on the server O/S(s). 

    As for a Windows workstation O/S machine, I have never seen DTC enabled on it, even for  Windows O/S workstation machines that had a desktop solution running on them a client/server solution with a backend server hosting MS SQL Server. 

    You want to turn DTC on, then turn it on there is nothing stopping you from doing it.

    However, EF Core does not work with DTC if you move to EF Core.

    • Marked as answer by duppino Thursday, May 21, 2020 7:25 AM
    Thursday, May 21, 2020 5:33 AM
  • It doesn't matter where/how many times your app is installed. The only thing that matters is how many machines are involved in the transaction. TransactionScope, in my experience, generally requires DTC (it'll up to distributed if needed) but is rarely actually needed.

    If you are talking to a single database (which you said you are) then TransactionScope is overkill and you do not need DTC. Just use BeginTransaction on the connection. The only time you need distributed transactions (and therefore TransactionScope) is if you're trying to update multiple databases (or other supported resources) across different machines.  Even if all your apps were talking to the same SQL database you don't need DTC. DTC is only needed if you are trying to perform a transaction across multiple resources on multiple machines. A single resource never needs DTC.

    Personally I recommend you switch to using BeginTransaction, turn off DTC and then let your app run. It'll let you know if it needed DTC but I wouldn't expect it to.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by duppino Thursday, May 21, 2020 8:37 PM
    Thursday, May 21, 2020 1:39 PM
    Moderator

All replies

  • Hello,

    I believe this is what you are looking for.

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/distributed-transactions


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, May 19, 2020 5:34 PM
    Moderator
  • I don't think you understand the purpose of the DTC, which is between computers. Therefore, you should just leave DTC disabled on the computer, becuase it does nothing for your program. 
    Tuesday, May 19, 2020 9:38 PM
  • You only need to turn on DTC if your queries are going to use transactions (e.g. TransactionScope) across database (or even non-database) resources at the same time. The purpose of DTC is to coordinate the update of the resources across potentially different machines. In the vast majority of cases you do not need DTC and in fact it'll slow things down.

    In my experience if DTC is not running then when you try to do a distributed update in a transaction then you'll get an error letting you know DTC is needed. If you never see that error then you don't need it. However I've seen a few cases where some connection string settings might imply the need for DTC as well even if it is not used.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by duppino Thursday, May 21, 2020 7:25 AM
    Wednesday, May 20, 2020 1:44 PM
    Moderator
  • Thanks for reply.
    But if my application is installed on 3 PCs, one of which acts as a server with the port open on sqlserver, is it needed to enable it?

    The three PCs also make calls with TransactionScope.
    Thanks
    d.
    Thursday, May 21, 2020 2:59 AM
  • DTC would be enabled on a Web server machine and  a server machine  that was hosting MS SQL Server as an example. Any ASP.NET Web solution that used a transaction scope on the Web server would participate in a distributed transaction scope across the two machines the server hosting IIS with the ASP.NET Web solution and the server hosting MS SQL Server. The two machines would have DTC enabled on the server O/S(s). 

    As for a Windows workstation O/S machine, I have never seen DTC enabled on it, even for  Windows O/S workstation machines that had a desktop solution running on them a client/server solution with a backend server hosting MS SQL Server. 

    You want to turn DTC on, then turn it on there is nothing stopping you from doing it.

    However, EF Core does not work with DTC if you move to EF Core.

    • Marked as answer by duppino Thursday, May 21, 2020 7:25 AM
    Thursday, May 21, 2020 5:33 AM
  • It doesn't matter where/how many times your app is installed. The only thing that matters is how many machines are involved in the transaction. TransactionScope, in my experience, generally requires DTC (it'll up to distributed if needed) but is rarely actually needed.

    If you are talking to a single database (which you said you are) then TransactionScope is overkill and you do not need DTC. Just use BeginTransaction on the connection. The only time you need distributed transactions (and therefore TransactionScope) is if you're trying to update multiple databases (or other supported resources) across different machines.  Even if all your apps were talking to the same SQL database you don't need DTC. DTC is only needed if you are trying to perform a transaction across multiple resources on multiple machines. A single resource never needs DTC.

    Personally I recommend you switch to using BeginTransaction, turn off DTC and then let your app run. It'll let you know if it needed DTC but I wouldn't expect it to.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by duppino Thursday, May 21, 2020 8:37 PM
    Thursday, May 21, 2020 1:39 PM
    Moderator