ASP transaction control function. By contacting the MTS service, IIS can control multiple transaction-supporting systems. Program When a "failed" signal is sent, all systems that support the transaction will automatically roll back, even if the operation has been formally completed; manual rollback is also convenient for operations that do not support transactions:
<% @ Transaction = required %>
On Error resume next
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open ....
Conn. Execute "insert ...."
Conn. Close
Set conn = nothing
Set conn2 = server. Createobject ("ADODB. Connection ")
Conn2.open ....
Conn2.execute "insert ...."
Conn2.close
Set conn2 = nothing
Set FSO = server. Createobject ("scripting. FileSystemObject ")
FSO. createfolder "...."
If err then
Objectcontext. setabort notifies all components that support transaction rollback and runs manual rollback.Code
Else
Objectcontext. setcomplete
End if
Set FSO = nothing
Sub ontransactionabort
Response. Write "error"
FSO. deletefile server. mappath ("a.txt") 'fso manual rollback -- delete folder
End sub
Sub ontransactioncommit
Response. Write "successfully completed the task"
End sub
%>
<% @ Transaction = required %> In the first line indicates that the ASP file on this page requires MTS transaction support. All the operations in the middle are written in the normal order, so you do not need to consider rollback. At the end of the program, determine whether there is an error. If the setabort method of objectcontext is called, IIS will notify all transaction-supporting components (mainly databases) to roll back through the MTS service ), run sub ontransactionabort to manually roll back operations that do not support transactions. If no error occurs, call the setcomplete method of objectcontext to run sub ontransactioncommit to display successful messages.
The entire ASP program does not need to write redundant code for judgment errors and rollback operations. It only needs to make judgment at the end, even if multiple steps are added in the future, you only need to control sub ontransactionabort, which is very convenient. programmers can focus on process writing rather than writing error correction code.