Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransactionScope bug in .NET? More information?

Tags:

I have read (or perhaps heard from a colleague) that in .NET, TransactionScope can hit its timeout and then VoteCommit (as opposed to VoteRollback). Is this accurate or hearsay? I couldn't track down information on the web that talked about this issue (if it IS an issue), so I wonder if anyone has any direct experience with it and can shed some light?

like image 647
Peter Mounce Avatar asked Oct 12 '08 12:10

Peter Mounce


People also ask

What is TransactionScope in asp net?

The TransactionScope class provides a simple way to mark a block of code as participating in a transaction, without requiring you to interact with the transaction itself. A transaction scope can select and manage the ambient transaction automatically.

Which namespace has TransactionScope class defined in Ado net?

TransactionScope is a class of System Namespace. It can also be termed as Transactions Namespace. The TransactionScope class supports transactions from code blocks and that is why it plays a key role in the . NET development framework.

What is meant by transaction class in Web technology?

The Transaction class contains methods used by developers implementing resource managers for enlistment. It also provides functionalities for cloning a transaction and controlling the current transaction context. You can obtain the current transaction, if one is set, using the static Current property.


2 Answers

The behaviour that Marc Gravell described has been changed in .Net 4.0. Instead of the operation being autocommitted, it will now throw an InvalidOperationException. So in 4.0 you no longer need to use Explicit Unbind.

like image 175
Jared Moore Avatar answered Oct 19 '22 22:10

Jared Moore


If you mean in relation to SQL Server, then there is an issue that you can fix in the connection string; see my reply here, or the full details here.

The short version is: ensure you have Transaction Binding=Explicit Unbind; in the connection string.

It isn't actually doing a vote commit - the transaction (and any early operations) has rolled back, but any subsequent operations (still inside the TransactionScope) can get performed in the nul-transaction, i.e. auto-commit.

like image 30
Marc Gravell Avatar answered Oct 19 '22 23:10

Marc Gravell