Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reliable test for MSDTC promoting transactions to distributed?

How can I reliably check that MSDTC has promoted a transaction to a distributed transaction?

This is when using TransactionScope in .net.

Currently a co-worker is testing this by shutting down the coordinator on his machine - if an exception is thrown this is taken as evidence that an attempt to promote the transaction has occurred. Is this a valid test?

like image 265
Oded Avatar asked Mar 16 '10 16:03

Oded


People also ask

How can I enable distributed transactions for a linked server?

On the server where the trigger resides, you need to turn the MSDTC service on. You can this by clicking START > SETTINGS > CONTROL PANEL > ADMINISTRATIVE TOOLS > SERVICES. Find the service called 'Distributed Transaction Coordinator' and RIGHT CLICK (on it and select) > Start. Save this answer.

What is the use of MSDTC in clustering?

MSDTC is a separate Windows service which coordinates distributed transactions across SQL Server instances. When deploying SQL Server in a highly available environment like Windows Failover Clustering, there are certain best practices that can make the MSDTC service's behavior more predictable.

How do I find my Distributed Transaction Coordinator?

Right-click My Computer, and then click Manage. Expand the Services and Applications node, and then click the Services node. In the right pane, locate the Distributed Transaction Coordinator. Right-click Distributed Transaction Coordinator, and then click Properties.


1 Answers

I think your test is OK although you should ensure that you are getting a DTC exception and not some other exception.

Some other things you could do:

  • You could also run SQL Profiler and under Transactions trace DTCTransaction.

  • In terms of code, you could handle the DistributedTransactionStarted event and log a message when a distributed transaction is started.

  • Or you could just add log messages to log the System.Transactions.Transaction.Current. TransactionInformation.DistributedIdentifier before the end of the transaction. If the value is Guid.Empty {00000000-0000-0000-0000-000000000000} then it is not a distributed transaction otherwise the transaction has been promoted to a distributed transaction.

You said you were using SQL Server 2008. What version of .NET are you using? Is it 3.5? If you are using SQL Server 2008 and .NET 3.5 then you should be able to open multiple connections (using the same connection string) to the same database in the same transaction without escalating to a distributed transaction. For this to work you need to close the first connection before opening a second connection.

If it appears that all the conditions are met and the transactions are still escalating, I would:

  • double check the SQL Server compatibility level
  • check the connection string to see if pooling is disabled
  • check to see that two connections are not opened at the same time in one transaction
  • find out if all transactions are being promoted or only in certain scenarios

UPDATE: The Distributed Transaction Coordinator(MSDTC) and Transaction FAQ pulls together a great list of MSDTC resources.

like image 133
Randy supports Monica Avatar answered Sep 21 '22 23:09

Randy supports Monica