How can you rollback a transaction?


#1

How do you rollback a transaction (without throwing an exception)? This didn’t work for me:

new DataAccessState().ExecuteWithThis(
    					() =>
    					DataAccessState.Current.PrimaryDatabaseConnection.ExecuteWithConnectionOpen(
    						() => DataAccessState.Current.PrimaryDatabaseConnection.ExecuteInTransaction( () => {
    DataAccessState.Current.PrimaryDatabaseConnection.RollbackTransaction();
    } ) ) );

Because:
System.ApplicationException: An exception occurred while rolling back a transaction for the primary database. —> System.ApplicationException: Cannot rollback without a matching begin.


#2

It ends up that throwing an exception is the best way.