ObjectContext Object

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.

Syntax

ObjectContext.method

Methods
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.
Events
OnTransactionAbort Event
OnTransactionCommit Event
Remarks

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.

Example

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>

FakePre-d930e4342ae249a48d25a3e06c885113-78520366cb1247fd929b7d769d43a61d