问题
Are there any tips, tricks or methods for obtaining profiling/logging/debug information on the runtime behaviour of System.Transactions.TransactionScope
?
I have an application which is committing data to the database, even though I'm using System.Transactions.TransactionScope
, where an exception is thrown and TransactionScope.Commit()
is never called.
I was wondering if there are events or details on other classes used by TransactionScope
that I can query at runtime to establish whether my commands (typed data adapters) are enlisting the ambient transaction or not.
Having looked at System.Transactions.dll
using Reflector, I think the System.Transactions.Diagnostics
namespace might help, but any examples would be much appreciated.
回答1:
Check-out this article: http://blogs.msdn.com/b/madhuponduru/archive/2008/02/18/system-transactions-trace.aspx
Add following info to your application config file to trace System.Transactions calls
<configuration>
<system.diagnostics>
<sources>
<source name="System.Transactions" switchValue="Information">
<listeners>
<add name="tx" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "tx.log" />
</listeners>
</source>
</sources>
</system.diagnostics>
MORE INFO: once you got trace file, you can open the trace in SvcTraceViewer.exe You can enable MSDTC transaction trace,CM trace to know more about transaction also Reference:
- http://msdn2.microsoft.com/en-us/library/ms229979.aspx
- http://msdn2.microsoft.com/en-us/library/ms678891.aspx
- http://support.microsoft.com/kb/926099/
- http://support.microsoft.com/kb/898918/
回答2:
Are you creating a transaction scope with parameters?
This behaviour would be expected for transaction scope option of Supress.
Otherwise could you post some code.
来源:https://stackoverflow.com/questions/1708714/advanced-system-transactions-debugging