Database.RollbackTransaction

From Xojo Documentation

Revision as of 12:41, 29 March 2021 by PLefebvre (talk | contribs) (Notes: Updated text to refer to BeginTransaction method added in API 2.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Method

Database.RollbackTransaction()

New in 2019r2

Supported for all project types and targets.

Cancels an open transaction restoring the database to the state it was in before the transaction began.

Notes

You will generally want to rollback database changes if a DatabaseException occurs within the transaction.

You have to have an open transaction to be able to use Rollback. Call BeginTransaction to begin a transaction:

DB.BeginTransaction]]

== Sample Code ==
This code uses rollback to revert database changes in a transaction when an error occurs:
<rbcode>
// Prior DB code has run

Try
db.CommitTransaction
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
db.RollbackTransaction
End If

See Also

Database.Close, Database.CommitTransaction