The disadvantages of utilizing TransactionScope New

.net c# entity-framework sql

Question

I'm curious about the drawbacks and risks associated with utilizingTransactionScopeOption.RequiresNew What are the reasons why we SHOULD NOT utilize EntityFramework (using SQL Server 2008)?RequiresNew always.

Regards.

1
13
4/22/2011 10:44:53 PM

Accepted Answer

You must useRequired not RequiresNew RequiresNew implies that regardless of whether there is an existing, all-inclusive transaction scope, every operation will utilize a new transaction. Deadlocks will undoubtedly result from this. even thoughRequired There is a significant issue withTransactionScope , specifically that it establishes a defaultSerializable transaction, a terrible decision that leads to deadlock nightmare and lack of scalability. Look at use of new TransactionScope() viewed negatively. A transaction scope should always be created with the explicitTransactionOption setting the amount of isolation toReadCommitted which a much more normal amount of isolation:

using(TransactionScope scope = new TransactionScope(
    TransactionScopeOption.Required,
    new TransactionOptions {
       IsolationLevel = IsolationLevel.ReadCommitted}))
{
   /// do work here
   ...
   scope.Complete();
}
23
8/23/2013 7:17:23 PM

Popular Answer

Just wanted to mention that, in a few specific circumstances, the method I wrote is within a parent transaction scope that may or may not be closed withscope.Complete() In these circumstances, I didn't want to be reliant on the parent transaction, therefore RequiresNew has to be set.

I do, however, concur that read committed should be used instead since it is not essential.

http://msdn.microsoft.com/en-us/library/ms172152(v=vs.90).aspx



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow