You can use the ObjectContext object to submit or discard a Transaction managed by Microsoft Transaction Server (MTS), which is initialized by the script contained on the ASP page.
When ASP contains the @ TRANSACTION command, the page runs in the TRANSACTION and ends until the TRANSACTION succeeds or fails.
Syntax
ObjectContext. method
Method
The SetComplete method declaration script does not understand the cause of transaction unfinished. If all components in the transaction call SetComplete, the transaction will be completed.
The SetAbort method declares that the transaction initiated by the script has not been completed and the source cannot be updated.
Event
OnTransactionCommit
OnTransactionAbort
Note
ObjectContext implements the MTS ObjectContext object in two ways. The SetAbort method completely terminates the transaction. In this way, MTS does not update the source of the first-stage contact. When the transaction ends, the OnTransactionAbort event of the script is processed.
Calling the SetComplete method does not necessarily mean that the transaction has been completed. The transaction can be completed only when SetComplete is called by all transaction components called by the script. In most instances, if SetAbort is not called at the end of processing, the script is generally assumed to be complete, so it is not necessary to call SetComplete in the script.
ObjectContext shows six methods except SetAbort and SetComplete. These methods can be used for components called by scripts, but cannot be used directly for ASP scripts.
Example
Here we use the SetAbort and SetCommit methods. The Sales.htm file obtains the data required to process the sales request. The script in the second file, SalesVerify. asp, uses two objects, Inventory and Sales, to process Sales. If the error code returned by Inventory indicates that the Inventory for sale is insufficient, SetAbort is called. If no error code is returned for the Inventory object, SetComplete is called to process the sales request.
Sales.htm
<! Doctype html public "-// IETF // dtd html // EN">
<HTML>
<HEAD>
<TITLE> Sales Order </TITLE>
</HEAD>
<Body bgcolor = "# FFFFFF"> <font face = "ARIAL, HELVETICA">
<H2> Sales Order Form </H2>
<Form method = post action = "SalesVerify. asp">
<P> Please enter the product code, quantity, and your account number.
<Input type = text name = QuantityToBuy>
<Input type = text name = ProductCode>
<Input type = text name = AccountIn>
<P>
<Input type = SUBMIT>
</FONT>
</BODY>
</HTML>
SalesVerify. asp file
<% @ Transaction = Required %>
<%
Set CurrentQOH = Server. CreateObject ("Mycomp. Inventory ")
Set CurrentSales = Server. CreateObject ("Mycomp. Sales ")
CheckQuantity = Request ("QuantityToBuy ")
CheckProduct = Request ("ProductCode ")
QuantityStatus = CurrentQOH. CheckQOH (CheckQuantity, CheckProduct)
If QuantityStatus = None
ObjectContext. SetAbort
Response. Write "Sorry, there is not sufficient quantity on hand to process your sale ."
Else
ObjectContext. SetComplete
Account = Request ("AccountIn ")
Saleupdate = CurrentSales. PostIt (AccountIn)
End If
%>