views:

221

answers:

1

Apparently (because the documentation doesn't say any word of this), in a .NET Transaction (using TransactionScope), the rollbacks are done in the same order as the commits would be, and in the same order as the registrations were done.

Logically, rollback should be in reverse order: If an action sequence is "do A" then "do B", my rollback sequence should be "undo B", then "undo A". But thanks to TransactionScope it's not, it's always "undo A", then "undo B".

Did I miss an option, or shall I die with this strange ordering ? :)

A: 

According to Microsoft, if your transaction scope goes "out of scope" (i.e. if you throw an exception from within the transaction scope) before the Complete() method is executed, the transaction within that scope should get rolled back immediately.

It follows that, if you want your transactions to roll back in reverse order, you should nest them. See the following article for more information:

Implementing an Implicit Transaction using Transaction Scope
http://msdn.microsoft.com/en-us/library/ms172152.aspx

Robert Harvey
I'm using transactions to implement a transactional filesystem (sort of). File operations can be done in a random order, and MUST be undone in reverse order. So I can not nest transactions. I guess I'm screwed and need to write my own list of file operations to reverse them in right order.
picrap
Mr. Picrap, any solution about your needs ??
alhambraeidos