DTC escalation (SqlDatabaseTraceListener)

Sep 23, 2013 at 7:00 AM

My application runs in a hosted environment where DTC is not available.
How do I stop my transactions from escalating to DTC. The application uses EF.

The logger is escalating transactions, which I need to avoid. Ideally I would like to make use of the log, my only other option is to remove all logging from inside transactions.
Sep 24, 2013 at 12:01 PM
Interesting situation.

1) Removing logging from the transaction is one option, as you suggested.


You could also use TransactionScopeOption.Suppress http://msdn.microsoft.com/en-us/library/system.transactions.transactionscopeoption.aspx

Wrapping the logging in this should execute it outside the ambient transaction created by EF, so it will not escalate to DTC.

2) If you have a central application logging component (e.g. that synchronises diagnostics tracing, application log and event log), or are simply happy to have a wrapper function, then you can do this on the logging side.

Note that this won't work for any diagnostics outside your control, e.g. from the Framework itself (e.g. if you have any Framework logging turned on from https://essentialdiagnostics.codeplex.com/wikipage?title=Integration&referringTitle=Guidance)

3) The other place this can be added is inside the TraceListener. I think this should be as simple as inheriting from the trace listener and then overriding the main logging method, WriteTrace() with something like:

using (new TransactionScope(TransactionScopeOption.Suppress)) {

To do this more fully it should probably be added as an option parameter, and I may include it in the component at some point -- I guess it would be fairly common for your diagnostics to be excluded from an ambient transactions (in fact I would probably make that the default).