12

I am experiencing this weird behavior where the transaction gets committed only when the using exits and not when calling scope.Complete();

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
       {
        scope.Complete();
           // data still doesn't show in db
       }
       // now shows in db

How do I commit the transaction before exiting the using statement?

user2312219
  • 443
  • 1
  • 5
  • 12
  • 1
    Committable Transaction is the only transaction which provides options to commit or rollback http://msdn.microsoft.com/en-us/library/system.transactions.committabletransaction.aspx – Sankara Apr 25 '13 at 12:15

1 Answers1

11

from the documentation:

The actual work of commit between the resources manager happens at the End Using statement if the TransactionScope object created the transaction.

So it doesn't look like you can truly commit the transaction before the using statement end.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
NDJ
  • 5,189
  • 1
  • 18
  • 27
  • 2
    The main reason is that it might be nested inside of another scope, so all you're saying is that "my work here is looking good" but a failure later on might still want to roll it back if it was part of a larger operation. – Darren Clark Jul 15 '16 at 19:55