views:

189

answers:

2

In .Net, is there any way to determine whether the ambient transaction is DTC transaction or not when debugging. I investigated SqlConnection class members but I found nothing. thanks.

+1  A: 

Set a breakpoint on the statement after the TransactionScope is instantiated, then execute the following command:

? System.Transactions.Transaction.Current

This will show you what type of Transaction you are enlisted in. If you are not in a DTC transaction, then you should see a System.Transactions.Ltm.LightweightTransaction.

From this MSDN article: ADO.NET and System.Transactions which also discusses when transactions get promoted to DTC.

Of interest: How to determine whether SqlConnection is enlisted into a System.Transactions' tx or not?

Mitch Wheat
Hi Micth, thanks for your response. But the link you provided is not helpful. Because I already knew that that is an enlisted transaction but I want to know whether the current transaction escaleted to Dtc transaction or not.
mkus
+5  A: 

I prefer to check the DistributedIdentifier Property.

In the immediate window while debugging type:

System.Transactions.Transaction.Current.TransactionInformation.DistributedIdentifier


If the value is Guid.Empty {00000000-0000-0000-0000-000000000000} then it is not a distributed transaction (the documentation says null but this is wrong since it is not a nullable type). Any other Guid value indicates that the transaction has been promoted to a distributed transaction.

Tuzo
+1. Nice one Tuzo.
Mitch Wheat