Click here to Skip to main content
15,741,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a transaction scope defined for my codes. But there is one thing I dont understand about the isolation level for transaction scope. If I have a line of code that is outside of the transaction scope, would the isolation level be inherited into the line of codes?
Below are my example:
using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionUtil.GetTransactionOptions(600)))
//do something here
//isolation level is ReadCommitted
//new line of codes here

Any help would be appreciated. Thank you.

What I have tried:

1. Researched online for article explanation.
Updated 28-Mar-16 3:48am

1 solution

This CodeProject article All About TransactionScope[^] goes into some detail about the TransactionScope class, which may help you.

You also need to be aware of an issue with the class for use with SQL Server - see this article using new TransactionScope() Considered Harmful | David Browne's Web Log[^]

My gut feel would be that the new lines of code would not inherit the isolation level, in the same way that if isolation level is set within a stored procedure in sql, the isolation level reverts back to whatever it was when the SP terminates. You can prove or disprove this by creating a new transaction (without setting isolation level) and querying the Transaction.IsolationLevel property.

If this is being used for a SQL Server connection then you can confirm or deny the behaviour by querying the Isolation Level currently on the connection (assuming you are using the same one) - This article has some C# code for doing that Getting and setting the Transaction Isolation Level on a SQL Entity Connection[^]

Try for the empirical evidence in whatever you are using TransactionScope for in your own code.

Personally I would never assume that the level is inherited and would explicitly set it myself.
Share this answer
Jamie888 28-Mar-16 21:46pm    
Sir, thank you for your explanation. If there is no transaction scope defined in codes, does it mean that the isolation level would be taken from the SQL database(isolation level generated through SQL)?
Jamie888 28-Mar-16 22:26pm    
Sir, I have found something in my codes which is TransactionScopeRequired is set to TRUE. Does this setting will make the whole method to be within a transaction scope and isolation level defaulted to SERIALIZABLE?
CHill60 29-Mar-16 6:02am    
The behaviour depends on other factors - see OperationBehaviorAttribute.TransactionScopeRequired Property (System.ServiceModel)[^]
It looks as if you have inherited this code from another developer - if they are still around then you should ask them what their intention was. If not then asking questions here is not a good way to learn - spend some time studying the basics e.g. How to: Create a Transactional Service[^]
Jamie888 29-Mar-16 21:54pm    
Thank you sir for your explanation, but unfortunately the developer is not around anymore. Anyway I will have a more detailed study on the transactionscope.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900