ASP Built-in Object ObjectContext detailed

Source: Internet
Author: User
Tags contains error code terminates
Object| Objects | built-in objects |

    You can use the ObjectContext object to submit or discard a transaction that is managed by Microsoft Transaction Server (MTS), which is initialized by the script that the ASP page contains. When the
  
  ASP contains @TRANSACTION directives, the page runs in a transaction until the transaction succeeds or fails to terminate.
  
  Syntax
  objectcontext.method
  
  method
  SetComplete The SetComplete method declares that the script does not understand why the transaction has not been completed. If all components in a transaction call SetComplete, the transaction completes. The
  SetAbort SetAbort method declares that the transaction initialized by the script has not completed and cannot update the source.
  
  Events
  OnTransactionCommit
  OnTransactionAbort
  
  Note
  ObjectContext two ways to implement the MTS ObjectContext object. The SetAbort method completely terminates the transaction. In this way, MTS does not update the source of the first phase contact. When a transaction terminates, the OnTransactionAbort event of the script is processed.
  
  Calling the SetComplete method does not necessarily mean that the transaction is complete. A transaction can be completed only if all the transaction components invoked by the script call SetComplete. In most instances, if SetAbort is not invoked at the end of the processing, the script is usually assumed to be complete, so it is not necessarily necessary to call SetComplete within the script.
  
  ObjectContext shows six methods outside of SetAbort and SetComplete. These methods are available to the components invoked by the script, but not directly to ASP scripts.
  
  Example

Here is a demonstration of how to use SetAbort and Setcommit. The sales.htm file gets the data needed to process the sales request. The script in the second file--salesverify.asp uses two objects--inventory and sales to process the sale. If Inventory returns an error code indicating that there is insufficient stock for sale, the SetAbort is invoked. If the Inventory object does not return an error code, it will call SetComplete 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" >

<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 isn't 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.