Search code examples
c#commitrollbacksqltransaction

How to check if Dotnet transaction is rolled back?


How Can I check if a dotnet transaction is closed or not ?


Solution

  • using(TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)){
    
        try{
            //Do something;
    
            scope.Complete();  //denotes the transaction completed successful.
        }
        catch(TransactionAbortedException ex)
        {
    
            //scope.Complete(); is never called, the transaction rolls back automatically.
        }
        catch(ApplicationException ex)
        {
    
        }
    }