A business is a series of operations that must be successful, and if one step fails, the other steps must be undone. In fact, in the database system, each SQL statement is a transaction, when executing this statement, either executes successfully, or executes the error and exits to the initial state. However, if you perform a set of SQL statements, you cannot revert to the original state when one of the steps fails, and you need to use the transaction processing mechanism to handle it.
ASP built-in components of the connection object, the main use of the transaction processing method has the following 3:
BeginTrans: For starting a transaction
CommitTrans: For completing/submitting a transaction
RollbackTrans: Rolling back
A simple example:
Copy Code code as follows:
On Error Resume Next
Objconn.begintrans ' Affairs started
More than one SQL statement
If Objconn.errors.count=0 Then
Objconn.committrans ' If there are no errors, execute transaction commits
Else
Objconn.rollbacktrans ' or roll back
End If