Microsoft KB Archive/299638

= How To Span a Transaction Across Multiple Active Server Pages =

Article ID: 299638

Article Last Modified on 3/29/2007

-

APPLIES TO


 * Microsoft Active Server Pages 3.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q299638





IN THIS TASK
SUMMARY
 * Prerequisites
 * Spanning Transactions Across Multiple ASP Pages
 * Troubleshooting

REFERENCES



SUMMARY
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.

back to the top

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

back to the top

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 &quot;Tran2.asp&quot;

Sub OnTransactionCommit Response.Write &quot; The Transaction just committed.&quot; Response.Write &quot;This message came from the &quot; Response.Write &quot;OnTransactionCommit event handler.&quot; End Sub

Sub OnTransactionAbort Response.Write &quot; The Transaction just aborted.&quot; Response.Write &quot;This message came from the &quot; Response.Write &quot;OnTransactionAbort event handler.&quot; 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: ObjectContext.SetAbort and save the file. </li> 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.

</li></ol>

back to the top

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.

back to the top

<div class="references_section">