What is MSDTC and why do I need to care about it?


I’ve been talking for a while about MSDTC and transactions without explaining them. I know many of you reading this blog already know the terms, but some of the developers just entering the enterprise space don’t know if they should care or not about these subjects.


MSDTC is an acronym for Microsoft Distributed Transaction Coordinator. As the name says, MSDTC is a Windows service providing transaction infrastructure for distributed systems. In this case, a transaction means a general way of structuring the interactions between autonomous agents in a distributed system. Each transaction is a state transformation with four key properties – the ACID properties: Atomic (all or nothing), Consistent (legal), Isolated (independent of concurrent transactions) and Durable (once it happens, it cannot be abrogated). There are different techniques that implement the ACID properties but the most known one is two-phase commit.


In other words, transaction processing is a software technology that makes distributed computing reliable. You can see a transaction as a unit of work in which a series of operations occur. The transaction (with its ACID properties) is providing protection in the case when one or more of these operations fail at any point in time. By using transactions, you can vastly simplify the error recovery for your system.


The main actors in a transaction are: the transaction manager (MSDTC), the initiator (the application which started the transaction) and the resource managers (the entities that manage data and work). The flow of actions in a simplified form is:


1. The client application (the initiator) begins a transaction by requesting one from the transaction manager;


2. The client app asks the resource managers to do work as part of the same transaction; during this step, the resource managers register with the transaction manager for that transaction (“they enlist”);


3. The client app commits the transaction;


4. The transaction manager coordinates with the resource managers to ensure that all succeed to do the requested work or none of the work if done, thus maintaining the ACID properties.


The main transactions standard currently supported by MSDTC is the OLE Transactions (or OleTx). MSDTC is also supporting other standards like XA (or X/Open Distributed Transaction Processing Standard) and TIP (Transaction Internet Protocol). In the future MSDTC will support WS-Coordination, WS-AtomicTransaction, and WS-BusinessActivity.


You can read more about MSDTC at http://msdn.microsoft.com/library/?url=/library/en-us/cossdk/htm/dtc_toplevel_6vjm.asp?frame=true.


If you are developing COM+ or System.EnterpriseServices components and you are using the Transaction service then you are indirectly using MSDTC. The COM+ infrastructure is hiding all the details from you so you can focus on your business needs instead of implementation details. If you need to bypass COM+ and talk directly to MSDTC you can do it using the MSDTC proxy (msdtcprx.dll). For now, to directly access MSDTC from .Net apps you need to use COM Interop. For future apps, please refer to my previous post about .Net and Transactions.

Comments (34)

  1. Hey dude…are you from Romania, right ?

    Nice post. I have 2 questions :

    – the System.Transactions in Longhorn. It’s all managed code, right? No more COM interop.

    – using this System.Transactions i can use transactions for anything..for instance…let’s say i have a web service which calls some business procedure. The BLL modifies a local db, then it calls a singletone remoting objects which modifies another database and after that i finally call yet another web services which modifies yet another database. Can i make this as s single those transactionable operation ?

    Cheers and thanks for the info.

  2. Christian Weyer: Web Services says:
  3. You’ve been Taken Out. Thanks for the Good Post!

  4. mjjsb says:

    transaction processing is a software technology that makes distributed computing reliable. You can see a transaction as a unit of work in which a series of operations occur. The transaction (with its ACID properties) is providing protection in the case when one or more of these operations fail at any point in time. By using transactions, you can vastly simplify the error recovery for your system.

    The main actors in a transaction are: the transaction manager (MSDTC), the initiator (the application which started the transaction) and the resource managers (the entities that manage data and work). The flow of actions in a simplified form is:

    1. The client application (the initiator) begins a transaction by requesting one from the transaction manager;

    2. The client app asks the resource managers to do work as part of the same transaction; during this step, the resource manages register with the transaction manager for that transaction (“they enlist”);

    3. The client app commits the transaction;

    4. The transaction manager coordinates with the resource managers to ensure that all succeed to do the requested work or none of the work if done, thus maintaining the ACID properties.

    The main transactions standard currently supported by MSDTC is the OLE Transactions (or OleTx). MSDTC is also supporting other standards like XA (or X/Open Distributed Transaction Processing Standard) and TIP (Transaction Internet Protocol). In the future MSDTC will support WS-Coordination, WS-AtomicTransaction, and WS-BusinessActivity.

  5. Gé Brander says:

    Hi,

    I still do not understand it. I have some problems regarding MSDTC on a cluster of Windows 2003 and SQL 2000. The application that connects to the database is using MSDTC and it is working fine (when I test it with WinRM0820 and DTCPING) from the one node of the cluster to the other node of the cluster, but from a different machine (not a cluster member) it is not working.

    It seems to be something with rights on file or registry, but I can not get hold on to it.

    What does the MSDTCPRX.DLL do? And where should it be registred?

    Thanks in advance

  6. Emilio says:

    And what about those firewall pop ups saying "application msdtc.* is trying to act as a server" ??? should I be worried about that?

  7. Florin Lazar says:

    Gheorghe,

    Thanks for the nice words. To answer your questions:

    1. In most of the cases System.Transactions will use only managed code. In the same time, it is possible that there will be parts in System.Transactions that will use COM Interop (for instance when talking to MSDTC using Oletx protocol). If performance is your concern, than you need to be aware that the price paid for going cross-process or cross-machine or writing to the disk (that happen when Oletx protocol is used) is considerably higher than the usage of COM Interop.

    2. We do our best to enable the scenario you are describing. When you put web services into the picture, Indigo will be the one that will smoothly enable the flow of the transaction between web services. Without Indigo, you can still flow transactions between web services but you have to take care of all the work. Also, without Indigo, you will lack the firewall friendliness of WS-Atomic Transactions.

  8. Florin Lazar says:

    Gé Brander,

    I recommend that you post your issue, with more details (for instance what action are you trying to do and how it fails, what error do you get?) to http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.platformsdk.complus_mts&lang=en&cr=US .

    Msdtcprx.dll is "the interface" you use to talk to MSDTC service to create, enlist, commit or abort transactions. You don’t have to register it, it comes with the OS.

  9. Florin Lazar says:

    Emilio,

    Msdtc is a "server" by definition. If you don’t use distributed transactions you can disable them on XP or W2K3 and those firewall pop-ups should go away.

  10. Sunil says:

    I have the current configuration, two machines in a cluster and MSDTC is running on both the machines but not as a cluster services. I am not able to start the Component Services window on any machine. The following error i am getting …

    ?????:error code 8004E00F-com+ was unable to talk to the Microsoft Distributed transaction coordinator

    The run-time environment was unable to initialize for transactions required to support transactional components.

    Make sure that MS DTC is running.(DtcGetTransactionManagerE): hr = 0x8004d01b)

    Please help. Thanks in Advance

  11. Florin Lazar says:

    Sunil,

    Standalone MSDTC on a cluster machine is not supported. MSDTC needs to be a cluster resource.

  12. Rama Gudimetla says:

    Hi Florin.. MSDTC looks good, but what about the transaction co-ordination that we can implement within the SQL server (using "begin transaction" and "commit transaction" within the stored procedures, for example). What advantages does MSDTC provide over that?

    Thank you..

  13. florinlazar says:

    Rama,

    MSDTC is about distributed transactions that span around multiple resource managers that can exist in a local or remote location.

    If you are using only one database, and your work is limited to a stored procedure than you probably don’t need MSDTC.

    With System.Transactions in Whidbey, we are putting in a place a mechanism called promotion that will allow you to use transactions with no "penalty" and to "pay for play" for each additional resource that you add to the transaction. The performance for System.Transaction using only one database that supports "promotable transactions" (Microsoft SQL Server 2005 does) is similar to using ADO.NET one database transaction operations.

  14. Esperpento says:

    PDC05

    The other day I mentioned some of the issues surrounding the appropriate scenarios for atomic…

  15. Kurt says:

    DTC sucks

  16. florinlazar says:

    To: Kurt

    Thanks for your feedback. Would you be able to share why do you think so? We are open to improve MSDTC.

  17. Sam says:

    I’m setting up a Win2003 cluster with SQL 2005 failover clustering. Microsoft recommends running MSDTC in a separate cluster group with its own name, ip, and disk resources. How large should my physical disk resource be for this MSDTC cluster group?

  18. florinlazar says:

    To: Sam

    MSDTC will store its log file on the physical disk in the cluster. By default, the size of the log file is 4MB. So, your disk size should be at least your log file size.

  19. Peter Manser says:

    It probably should be installed but not active by default, and set to automatically start when an application requiring it’s functionality is installed.

    This would reduce overheads and the security concerns of those who don’t use it.

  20. florinlazar says:

    To: Peter Manser

    On client machines (XP or Vista), the service is not started by default. It will demand-start when an application will try to use transactions.

  21. Aileen says:

    I am a bit confused. When we setup our MS & SQL Cluster we decided that we didn’t need MS DTC. Now we are getting ready to install SP1 and from the docs it sounds like we absolutely need to install and configure this service. Is this true?? Our cluster is ONLY for Failover, not Load Balancing.  Please advise.

  22. Nizam says:

    I have been facing a problem with my Business (COM) object hosted on Application server(windows 2003) in COM+ with transaction set as required new. The COM internally calls DB objects which have a function to update MS SQL database table(using Stored Proc) on a different machine(Windows 2003 cluster).

    Network DTC is enabled on both machines and MSDTC is configured on windows cluster as well.

    Fetch and insert work fine only problem with updates.

    Some times the update works fine and some times it throws a SQL time out error.

    Could anyone help me in troubleshooting this.

    Thanks in advance..

  23. florinlazar says:

    To: Aileen

    Yes, on W2K3 cluster, the MSDTC needs to be a clustered resource if you or any app needs to use it for transactions. MS SQL Server is using MSDTC transactions.

  24. Kwan says:

    Hi Florin,

    Is MSDTC working in Windows 2003 (Web Edition) with SP1?

    I write a very simple .NET WebService that calls out a ServicedComponent.

    But it throws an exception:

    The run-time environment was unable to initialize for transactions required to support transactional components. Make sure that MS-DTC is running. (DtcGetTransactionManagerEx(): hr = 0x80070005)

    The whole test and same setup work for Windows 2003 (Standard Edition) with SP1.  So I only have problem for Web Edition.

    BTW, there is another post with the same error:

    http://groups.google.ca/group/microsoft.public.windows.server.general/browse_thread/thread/13c4404d6c065bb3/9ee468093d69979d?lnk=st&q=rob+livermore+com%2B&rnum=1&hl=en#9ee468093d69979d

    I can provide my test program if you are interested.

    Thanks.

    Kwan

  25. Mark Minasi says:

    Hi Florin,

    Nice writeup, thanks! My question may be out of your scope; if so then just let me know.

    I’m not a coder, but I’d thought before that MSDTC’s job was to make setting up and doing an ACID transaction simple from a coder’s point of view. Now I see (I think) that MSDTC’s raison d’etre is more than just ACID, and the key word is DISTRIBUTED… in other words, MSDTC’s power lies in being able to update many different database servers simultaneously. (Right?)

    Anyway, us admin guys have been stumbling over MSDTC since 2003 SP1 because domain controllers all complain that they couldn’t process a DCPROMO event. I know, there’s a workaround — go to the Security tab, exit it, return and sometimes the problem goes away. But that’s not what I’m wondering.

    Is the reason that Active Directory even cares about MSDTC is that MSDTC has a major role in helping LSASS, Netlogon and the gang keep multiple domain controllers in sync? That’d be odd, as I’m pretty sure that I’ve disabled MSDTC on DCs in the past without trouble.

    Basically I’m just looking for some insights on what effect MSDTC has on Active Directory. Thanks!

  26. florinlazar says:

    To: Kwan

    There is a known issue with SP1 Web Edition for Server 2003.

    To workaround the issue, you can run the following commands:

    reg add "HKLMsoftwaremicrosoftwindows ntcurrentversioncluster server"

    reg add "HKLMsoftwaremicrosoftwindows ntcurrentversioncluster server" /v ClusterInstallationState /d 1 /t REG_DWORD

  27. florinlazar says:

    To: Mark Minasi

    If you are referring to

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=419544&SiteID=1

    then the answer is that currently MSDTC has no effect on Active Directory (yet).

    The security settings for MSDTC are different depending on the fact that the machine is a DC or not (tigher settings on DC). When a machine is promoted/demoted to/from a DC, the AD is sending a notification to MSDTC. When MSDTC is trying to change its config, it fails due to a permission bug.

  28. arunr14 says:

    Hello

    i am a entry level enterprise developer , so please bare with my ignorance. Currently we have a com+ application ( Factelligence  , used widely in the manufacturing industry) . It has certain API’s to create inventory etc .  and we will be writing our own libraries to work along side of Factelligence. Am i right to assume that any database calls made by the Factelligence API will go through the MSDTC ? . i am not really concerned about multiple databases but more about reliable transaction control. I appreciate your help.

  29. florinlazar says:

    To: arunr14

    COM+ uses MSDTC

  30. arunr14 says:

    Thank you for your reply. Following up on my previous comment ,Is it possible   to combine the Transaction created by the COM+ application and my custom commands into one before sending it to the database?

  31. florinlazar says:

    To: arunr14

    Yes, you can combine the trasaction that COM+ is using with other transacted work.

    I do recommend posting at the Transactions Forum http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=388&SiteID=1

  32. ejeggle says:

    Hi All,

    I have a new windows Vista 64 machine, and have really enjoyed it so far.

    I had a slight problem in my eventviewer which sent me on a bit of a search. I eventually came onto the COM+ Services and while trying to troubleshoot that I found out that my MSDTC service doesnt work.

    I have searched High and Low, I have tried all the tips and tricks I could find, the regestry entries look like they should, msdtc -uninstall (seemed to work), msdtc -install seems to do nothing, neither does msdtc -resetlog.

    Now MSDTC is no longer a service in my services panel, so I think the un-install worked . . .

    My question is – Do I need MSDTC? My pc is a stand alone, no AD etc, it is a home pc. Do I need the MSDTC service?

    Obviously without it I get an error in compexp.msc when trying to access COM+ Applications.

    Thanks for any feedback!

    Regards

    Eugen