asp transaction processing
Author:Eve Cole
Update Time:2009-06-24 17:28:33
When a large number of operations such as inserting, modifying, and deleting are performed on the database, if you want to implement transactions, you can use the following code. like:
<%@ TRANSACTION = Required%>
On Error Resume Next
strSql1="insert into a(num) values(1)"
strSql2="insert into a(num) values('a')"
'Execute the first sql statement
'Execute the second sql statement
'If no transaction is used, the first sql statement will be submitted to the database.
'In addition, after checking the database, it was found that the transaction rollback of the database actually performed the corresponding reverse operation. When insert is executed, delete operation will be executed during rollback. It can be obtained by watching the changes of primary key id.
If Err Then
ObjectContext.SetAbort 'Notify all components that support transactions to roll back
Else
ObjectContext.SetComplete
End If
SubOnTransactionAbort
Response.Write "Error"
'Note that if some non-database operations were used previously, such as file operations, creating files, deleting files, etc. The rollback operation of the file needs to be added here. If you create a file earlier, you need to delete the file accordingly.
End Sub
SubOnTransactionCommit
Response.Write "success"
End Sub