Platform SDK: IIS SDK |
You can use the ObjectContext object to either commit or abort a transaction, managed by Component Services, that has been initiated by a script contained in an ASP page.
When an .asp file contains the @TRANSACTION directive, the page runs in a transaction and does not finish processing until the transaction either succeeds completely or fails.
ObjectContext.method
ObjectContext.SetAbort | Declares that the transaction initiated by the script has not completed and that the resources should not be updated. |
ObjectContext.SetComplete | Declares that the script is not aware of any reason for the transaction not to complete. If all components participating in the transaction also call SetComplete, the transaction completes. |
OnTransactionAbort Event |
OnTransactionCommit Event |
The ASP ObjectContext object implements two methods of the COM+ ObjectContext object. The SetAbort method explicitly aborts the transaction. This causes Component Services to prevent any updates to resources that were contacted during the first phase of the transaction. When the transaction aborts, the script's OnTransactionAbort event will be processed.
Calling the SetComplete method does not necessarily mean that the transaction is complete. The transaction will only complete if all of the transactional components called by the script call SetComplete. In most instances, you will not need to call SetComplete within the script, as the script is assumed to be complete if it finishes processing without calling SetAbort.
The COM+ ObjectContext object exposes methods in addition to SetAbort and SetComplete. These other methods are not available to ASP scripts; however, they are available to COM+ components that can be called by the ASP scripts.
The following example uses the SetAbort and SetComplete methods. The first example file, Sales.htm, obtains data required to process a sales request. The second file, SalesVerify.asp, contains a script that uses two objects, Inventory and Sales, to process the sale. SetAbort is called if Inventory returns an error code indicating that there is not sufficient inventory on hand to process the sale. If the Inventory object does not return the error code, SetComplete is called and the sale is processed.
--- 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 ---
<%@ Transaction =index.html 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
%>
Platforms: Windows 2000 with IIS 5.0 installed,
Windows XP with IIS 5.1 installed,
Windows Server 2003 family with IIS 6.0 installed
What did you think of this topic? |
Order a Platform SDK CD |
file: /Techref/language/asp/obj/ref_vbom_obco.htm, 6KB, , updated: 2003/5/15 13:13, local time: 2024/12/11 12:58,
3.139.86.65:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/language/asp/obj/ref_vbom_obco.htm"> ObjectContext Object</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.