简体   繁体   中英

C# System.Transaction.RollBack

**

EDIT:

Okay , thanks for the anser. so what is the purposeof transactions if it isnt use for SQL? This article show an example of using simple transactions:

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

what is the purpose of this if it isnt for rolling back what ever they trying to restore in case the code fail? and what is tge diff between ambient transaction and normal transaction?

    void RootMethod()
{
     using(TransactionScope scope = new TransactionScope())
     {
          /* Perform transactional work here */
          SomeMethod();
          scope.Complete();
     }
}

void SomeMethod()
{
     using(TransactionScope scope = new TransactionScope())
     {
          /* Perform transactional work here */
          scope.Complete();
     }
}

TransactionScope is an ambient transaction for providers that detect and support it, such as ADO.NET database connection providers.
Not a magic wand to revert any changes you make inside your program. It just does not work this way.

If you create a TransactionScope , then create a database connection, then do something to the database using that connection, and then rollback the transaction scope, your changes to the database will be undone as if you issued a ROLLBACK TRAN against it.
Nothing more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM