A transaction is a series of operations that must be successful. If one operation fails, other steps must be undone. In fact, in the database system, each SQL statement is a transaction. When this statement is executed, it is either executed successfully, or an error is executed and exited to the initial state. However, if you execute a group of SQL statements, when one of the steps fails, it cannot be restored to the initial state. At this time, you need to use the transaction processor mechanism for processing.
The connection object in the ASP built-in component mainly uses the following three methods for transaction processing:
Begintrans: Used to start a transaction
Committrans: Used to complete/commit a transaction
Rollbacktrans: rollback
A simple example:CopyCodeThe Code is as follows: on error resume next
Objconn. begintrans 'transaction start
Multiple SQL statements
If objconn. errors. Count = 0 then
Objconn. committrans: If no error occurs, the transaction is committed.
Else
Objconn. rollbacktrans 'otherwise, roll back
End if