Monday, June 30, 2014

TransactionScope and MSDTC

Following up on this, I found this which suggests there is a MSDTC (Microsoft Distributed Transaction Coordinator) service in Windows which the TransactionScope type in C# will use to wrap database calls, called out within its using statements like so...

using (TransactionScope scope = new TransactionScope())
{
   PutSomethingInTheDatabase();
   AddSoftReferencesToThatOtherTable();
   scope.Complete();
}

 
 

...thus allowing for the rolling back of writes to a database should something fail midstream in a process. In the System.Transactions namespace lives the C# TransactionScope type which subclasses IDisposable as is clearly obvious when you look at the above code. This hints that one may make the MSDTC interface with two different datasources at the same time! Only one datasource may be used with MSDTC in its default setting and also in its absence, and yes, as this suggests, there is a way to forgo using MSDTC whatsoever with TransactionScope. You may not want use MSDTC on a project because one has to open up some particular ports that perhaps you'd rather not expose.

No comments:

Post a Comment