.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Determining Transaction Outcome

Posted By:Shashi Ray       Posted Date: November 30, 2009    Points: 25    Category: .Net Framework    URL: http://www.dotnetspark.com  

Determining Transaction Outcome

The outcome of an automatic transaction is governed by the state of the transaction abort flag, together with the consistent flags, in the context of all transactional components in a single transaction stream. Transaction outcome is determined at the point that the root component in the transaction stream is deactivated (and control is returned to the caller).

The outcome of the transaction is determined when the root object is deactivated, and the client's method call returns. If any of the consistent flags within any context are set to false, or if the transaction abort flag is set to true, the underlying physical DTC transaction is aborted.

You can control transaction outcome from a .NET object in one of two ways:

  • You can annotate methods with the AutoComplete attribute, and let .NET automatically place your vote governing the outcome of the transaction. With this attribute, if the method throws an exception, the consistent flag is automatically set to false (which ultimately causes the transaction to abort). If the method returns without throwing an exception, the consistent flag is set to true, which indicates that the component is happy for the transaction to commit. This is not guaranteed because it depends on the votes of other objects in the same transaction stream.
  • You can call the static SetComplete or SetAbort method of the ContextUtil class, which sets the consistent flag to true or false, respectively.

SQL Server errors with a severity greater than 10 result in the managed data provider throwing exceptions of type SqlException. If your method catches and handles the exception, be sure to either manually vote to abort the transaction, or for methods flagged as [AutoComplete], ensure that the exception is propagated to the caller.


Shashi Ray

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend