Question

Looking into it I verified that for example the value o "myInt" is not rolledback in the following scenario

int myInt = 10;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    myInt=20;
    Transaction t = Transaction.Current;

    t.Rollback();
}

So it got me thinking "Does a TransactionScope only rollback activities related to the database? Or there are other things that the Transaction can manage and I'm unware of those?"

Was it helpful?

Solution

Current transaction affects only specific objects, that are called Resource Managers. Those object must implement specific interfaces to participate in transaction. ADO.NET SqlConnection object is an example. It is not difficult to create an object that works as "Transactional Memory". Those objects are called Volatile Resource Managers. A simple example is here.

OTHER TIPS

TransactionScope (and Transactions) are only used for handling database queries. It wouldn't really make sense to "rollback" changes that are only kept around temporarily anyway, (such as your int variable).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top