12

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?"

asgerhallas
  • 16,890
  • 6
  • 50
  • 68
Leonardo
  • 10,737
  • 10
  • 62
  • 155

2 Answers2

21

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.

Slava
  • 1,065
  • 5
  • 11
-4

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).

crazylpfan
  • 1,038
  • 7
  • 9
  • -1 what you said makes no sense at all... what if i was saving this value to a text file? it would rollback then? – Leonardo Mar 07 '13 at 18:50
  • No, I meant non persistent data. A FileWriter would have its own mechanism for "rolling back" changes, you still can't use TransactionScope. – crazylpfan Mar 07 '13 at 19:32