ObjectContext Object (IIS)
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.
The ObjectContext object defines the following methods.
Declares that the transaction initiated by the script has not completed and that the resources should not be updated.
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.
The ObjectContext object defines the following events.
Occurs if the transaction is aborted. When the OnTransactionAbort event occurs, IIS will process the script's OnTransactionAbort subroutine, if it exists.
Occurs after a transactional script transacts. When the OnTransactionCommit event occurs, IIS will process the script's OnTransactionCommit subroutine, if it exists
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.
IIS 5.1 and earlier: Adding the ObjextContext object to the Application collection causes ASP error 0197 because it is not allowed on these versions of IIS.
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 = 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 %>
Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.