Cannot Get Back Ambient Transaction After Using Nested Suppress TransactionScope RRS feed

  • Question

  • I am trying to incorporate the use of TrasactionScope in our existing DAL and have not been able to find a solution to my problem despite hours of searching. The issue I have is that we are using transactions for some of the DB calls we have within any given postback (ASP.Net). I have modified our DAL to use a TransactionScope instead. In many instances, we are making some calls to the DB that do not need to be included in the transaction. So I have used TransactionScopeOption.Supress. However, this is being used to open a DataReader (code lookups) and I have yet to figure out how to "close" this scope and get back my ambient transaction once I am done with the reader. Because of the way our existing DAL works, I cannot create, use and dispose of the reader/TransactionScope all within a using block. And since the reader doesn't have any reference to the DB connection, let alone the TransactionScope, I don't know how to indicate that it is complete, or even to simply dispose of it.

    Anyone have any suggestions? I am wondering if I can't somehow manually reset the ambient transaction? As it is, I receive a "TransactionScope Nested Incorrectly" error.

    Tuesday, March 8, 2011 10:47 PM


  • Hi,

    Please refer below to understand how to "close" the transactionscope, when used in DAL.  The best practice here is that you create a transaction just before you need it and open your connection immediately before you execute DB  commands on them, and complete/dispose the transaction.   This also talks about how you can nest the transactionscopes.


    As for accessing the ambient transactions, you can use System.Transactions.Transactions.Current property.

    Can you share more details on what is causing the "TransactionScope Nested Incorrectly".




    Thursday, March 10, 2011 7:49 AM