The so-called transaction refers to a series of operations that must be successful. As long as one operation fails, other steps must also be cancelled. In fact, in the database system, each SQL statement is a transaction. When executing this statement, it will either be executed successfully or an error will be executed and exited to its original state. However, if an operation of a set of SQL statements is performed, when an error occurs in one of the steps, it cannot be restored to the original state. At this time, the transaction processing mechanism needs to be used to handle it.
The Connection object in ASP built-in components mainly uses transaction processing methods:
BeginTrans: Used to start a transaction
CommitTrans: Used to complete/commit a transaction
RollBackTrans: Rollback
A simple example:
The code copy is as follows:
onerrorresumenext
objConn.BeginTrans' transaction begins
Multiple SQL statements
IfobjConn.Errors.Count=0then
objConn.CommitTrans' If there is no error, the transaction commit is executed
else
objConn.RollbackTrans' Otherwise rollback
EndIf