ASP transaction Processing

Source: Internet
Author: User
Tags rollback
When a large number of database inserts, modify, delete and other operations, if you want to implement transactions, you can use the following code. Such as:
<%@ 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 a second SQL statement
' If the transaction is not present, the first SQL statement is committed to the database.
' Another view of the database found that the transaction rollback of the database is actually a corresponding reverse operation. When the insert is executed, a delete operation is performed in the rollback. Can be obtained by watching the change of the primary key ID.
If ERR Then
ObjectContext.SetAbort ' notifies all supporting transaction components to roll back
Else
ObjectContext.SetComplete
End If
Sub OnTransactionAbort
Response.Write "Error"
' Note that if you use some database-related operations, such as file manipulation, file creation, file deletion, etc. You need to add a rollback operation for the file here. Before the file is created, the corresponding deletion file is required here.
End Sub
Sub OnTransactionCommit
Response.Write "Success"
End Sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.