Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 299638 - Last Review: March 29, 2007 - Revision: 3.4
How To Span a Transaction Across Multiple Active Server Pages
This article was previously published under Q299638
This step-by-step procedure demonstrates how to use the
@TRANSACTION directive so that a transaction spans across multiple Active
Server Pages (ASP) pages. If you want to span a transaction across multiple ASP
pages, you must use the @TRANSACTION directive for each of the pages that will
participate in the transaction.
Prerequisites
This list outlines the recommended hardware, software, network
infrastructure, and service packs that you will need:
- Microsoft Active Server Pages, version 3.0
- Microsoft Internet Information Server 5.0
- Microsoft Windows 2000 Professional, Windows 2000 Server,
or Windows 2000 Advanced Server
This article assumes that you are familiar with the following
topics:
- Creating Active Server Pages
- Transactions
Spanning Transactions Across Multiple ASP Pages
- In Notepad, create a new ASP page named Tran1.asp, and
paste the following code (in which the Transaction directive is set to
Required):
<%@ TRANSACTION=Required %>
<%
Server.Execute "Tran2.asp"
Sub OnTransactionCommit()
Response.Write "<p><b>The Transaction just committed</b>."
Response.Write "This message came from the "
Response.Write "OnTransactionCommit() event handler."
End Sub
Sub OnTransactionAbort()
Response.Write "<p><b>The Transaction just aborted</b>."
Response.Write "This message came from the "
Response.Write "OnTransactionAbort() event handler."
End Sub
%>
NOTE: When the Transaction directive is set to Required, the ASP page
starts a transaction if one does not exist or joins an existing parent
transaction. - On the File menu, click Save. In the Save in drop-down list box, click the C:\Inetpub\Wwwroot folder. In the Save as type drop-down list box, click All Files. In the File name list box, type Tran1.asp. Close the
file.
- In Notepad, create a new ASP page named Tran2.asp, and
paste the following code (in which the Transaction directive is set to
Supported):
<%@ TRANSACTION=Supported %>
<%
ObjectContext.SetComplete
%>
NOTE: When the Transaction directive is set to Supported, the ASP page
joins the parent transaction, which Tran1.asp starts. This is also referred to
as enlisting-in-transaction. - On the File menu, click Save. In the Save in drop-down list box, click the C:\Inetpub\Wwwroot folder. In the Save as type drop-down list box, click All Files. In the File name list box, type Tran2.asp. Close the
file.
- In your Web browser, run Tran1.asp (for example, go to
http://localhost/Tran1.asp). Notice that Tran1.asp (with the Required
transaction value) starts a transaction and then runs Tran2.asp (with the
Supported transaction value), which calls the ObjectContext.SetComplete method to commit the transaction. The following output is
returned:
The Transaction just committed.This message came from the OnTransactionCommit() event handler.
- In Tran2.asp, change the following code
ObjectContext.SetComplete
to: and save the file. - In your browser, run Tran1.asp again. Notice that the
following output is returned, which shows that the transaction that aborted in
Tran2.asp is propagated to Tran1.asp:
The Transaction just aborted.This message came from the OnTransactionAbort() event handler.
Troubleshooting
The @TRANSACTION directive must appear on the first line in the
ASP page and is usually included with the @LANGUAGE directive. If anything
appears before this in the page, a script error occurs.
For more information about the @TRANSACTION directive, see
the following MSDN article:
APPLIES TO
- Microsoft Active Server Pages 3.0
- Microsoft Internet Information Services 5.0
| kbhowtomaster kbtransaction KB299638 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate