150 lines
6.4 KiB
HTML
150 lines
6.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
|
|
<TITLE>ObjectContext Object</TITLE>
|
|
<SCRIPT LANGUAGE="JavaScript">
|
|
<!--
|
|
TempString = navigator.appVersion
|
|
if (navigator.appName == "Microsoft Internet Explorer"){
|
|
// Check to see if browser is Microsoft
|
|
if (TempString.indexOf ("4.") >= 0){
|
|
// Check to see if it is IE 4
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
|
}
|
|
else {
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
|
}
|
|
}
|
|
else if (navigator.appName == "Netscape") {
|
|
// Check to see if browser is Netscape
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
|
}
|
|
else
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
|
//-->
|
|
</script>
|
|
<SCRIPT LANGUAGE="VBScript">
|
|
<!--
|
|
Sub Window_OnLoad()
|
|
Dim frmContents
|
|
On Error Resume Next
|
|
If Not Parent Is Nothing Then
|
|
Set frmContents = Parent.Contents
|
|
If Not frmContents Is Nothing Then
|
|
frmContents.Window.TOCSynch_Click
|
|
End If
|
|
End If
|
|
End Sub
|
|
//--></SCRIPT><META NAME="DESCRIPTION" CONTENT="Internet Information Services reference information">
|
|
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
|
|
<META NAME="MS.LOCALE" CONTENT="EN-US">
|
|
<META NAME="MS-IT-LOC" Content="Internet Information Services">
|
|
</HEAD>
|
|
|
|
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
|
|
|
|
<H2><A NAME="_objectcontext_object"></A><SUP></SUP>ObjectContext Object</H2>
|
|
|
|
<P>You can use the <B>ObjectContext </B>object to either commit or abort a transaction, managed by Component Services, that has been initiated by a script contained in an ASP page.</P>
|
|
|
|
<P>When an .asp file contains the <A HREF="/iishelp/iis/htm/asp/dire5t0u.htm">@TRANSACTION</A> directive, the page runs in a transaction and does not finish processing until the transaction either succeeds completely or fails.</P>
|
|
|
|
<H6>Syntax</H6>
|
|
|
|
<P><B>ObjectContext</B>.<I>method</I></P>
|
|
|
|
<P><I> </I></P>
|
|
|
|
<H6>Methods</H6>
|
|
|
|
<TABLE border=0 cellpadding=5 cols=2 frame=box rules=all>
|
|
|
|
<TR VALIGN="top">
|
|
<TD width=28%><A HREF="/iishelp/iis/htm/asp/vbob74l0.htm"><B>SetAbort</B></A></TD>
|
|
<TD width=72%>The <B>SetAbort</B> method declares that the transaction initiated by the script has not completed and the resources should not be updated.</TD>
|
|
</TR>
|
|
|
|
<TR VALIGN="top">
|
|
<TD width=28%><A HREF="/iishelp/iis/htm/asp/vbob9gpx.htm"><B>SetComplete</B></A></TD>
|
|
<TD width=72%>The <B>SetComplete</B> method 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 <B>SetComplete</B>, the transaction will complete.</TD>
|
|
</TR>
|
|
</TABLE><BR>
|
|
|
|
<H6>Events</H6>
|
|
|
|
<TABLE border=0 cellpadding=5 cols=1 frame=box rules=rows>
|
|
|
|
<TR VALIGN="top">
|
|
<TD width=100%><A HREF="/iishelp/iis/htm/asp/vbob7z78.htm">OnTransactionAbort</A></TD>
|
|
</TR>
|
|
|
|
<TR VALIGN="top">
|
|
<TD width=100%><A HREF="/iishelp/iis/htm/asp/vbob1n04.htm">OnTransactionCommit</A></TD>
|
|
</TR>
|
|
</TABLE><BR>
|
|
|
|
<H6>Remarks</H6>
|
|
|
|
<P><B>ObjectContext</B> implements two methods of the COM <B>ObjectContext</B> object. The <B>SetAbort</B> 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 <B>OnTransactionAbort</B> event will be processed.</P>
|
|
|
|
<P>Calling the <B>SetComplete</B> 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 <B>SetComplete</B>. In most instances, you will not need to call <B>SetComplete</B> within the script, as the script is assumed to be complete if it finishes processing without calling <B>SetAbort</B>.</P>
|
|
|
|
<P><B>ObjectContext</B> exposes methods in addition to <B>SetAbort</B> and <B>SetComplete</B>. These other methods are not available to scripts in ASP scripts; however, they are available to components called by the script.</P>
|
|
|
|
<H6>Example</H6>
|
|
|
|
<P>The following example uses the <B>SetAbort</B> and <B>SetComplete</B> methods. The Sales.htm file obtains data required to process a sales request. The second file, SalesVerify.asp contains a script that uses two objects, <B>Inventory</B> and <B>Sales</B>, to process the sale. <B>SetAbort</B> is called if <B>Inventory</B> returns an error code indicating that there is not sufficient inventory on hand to process the sale. If the <B>Inventory</B> object does not return the error code, <B>SetComplete</B> is called and the sale is processed.</P>
|
|
|
|
<P><B>Sales.htm</B></P>
|
|
|
|
<PRE><CODE><!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>
|
|
</CODE></PRE>
|
|
|
|
<P><B>SalesVerify.asp file</B></P>
|
|
|
|
<PRE><CODE><%@ 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
|
|
%>
|
|
</CODE></PRE>
|
|
|
|
<P>For more information, see <A HREF="iiaptran.htm">Understanding Transactions</A>.</P>
|
|
<hr class="iis" size="1">
|
|
<p align="center"><em><a href="../../../common/colegal.htm">© 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
|
|
</BODY>
|
|
</HTML>
|