Will a using statement rollback a database transaction if an error occurs?
Solution 1:
Dispose method for transaction class performs a rollback while Oracle's class doesn't. So from transaction's perspective it's implementation dependent.
The using
statement for the connection object on the other hand would either close the connection to the database or return the connection to the pool after resetting it. In either case, the outstanding transactions should be rolled back. That's why an exception never leaves an active transaction lying around.
Also, yes, you should call Commit()
explicitly.
Solution 2:
You have to call commit. The using statement will not commit anything for you.
Solution 3:
I believe that if there's an exception such that Commit()
was never called, then the transaction will automatically rollback.