Detailed description of asp built-in object ObjectContext

Source: Internet
Author: User
Tags error code

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
%>

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.