Transactional Active Server Pages

In this chapter, we have looked at how you can group business functionality together inside of a transaction using MTS. With the integration of MTS and IIS, you can now include Active Server Pages scripts within a transaction. These scripts can include calls to server components that will also participate in the transaction. As with all transactions, if any one part of the transaction fails, then the entire transaction will be rolled back. The added advantage of transactional ASP scripts is that it makes it easy to tie multiple components together into one transaction.

There is one problem with using transactional scripts when dealing with a transaction that aborts. The changes that were made to databases accessed with the database's Resource Manager will be automatically rolled back. However, as of this release of MTS, the environment is unable to rollback changes made within the script itself. Any changes made using the script, such as changes to session or application variables, will not be automatically rolled back. However, you will see later how to use transactional events to be notified that a transaction has aborted. When you handle this event, you can manually rollback any changes that MTS cannot perform automatically.

You cannot have one transaction that spans multiple ASP script pages. If there is work from multiple components that you want to include in the same transaction, then you will need to call all of those components from the same ASP script. For example, there is an application that has one component to withdraw money from an account and one component to deposit money into an account. To transfer funds from one account to another, you would create an ASP script that used the withdrawal component to get the funds for transfer and the deposit component to put that money in the new account. All of this functionality would be put in a transaction ASP script, so that if any part failed, all of the account balances would be reset to their initial values.

To declare a script as transactional, you would use the following directive:

<%@ TRANSACTION = transParam %>

The transParam value can have the following values:

Requires_New Starts a new transaction.
Required Starts a new transaction.
Supported Does not start a transaction.
Not_Supported Does not start a transaction.

These values have the same effect as the settings for the transaction participation states that can be set for each component using the MTS Explorer.

This directive must be on the first line in the ASP script. If there is anything before this in the page, then a script error will be generated. There is no explicit indicator to show that a transaction has ended. The transaction ends when the script reaches the end of the current page. MTS will create a transaction context for the page. Each object that is called by the page can use this context to participate in the transaction. The transactional ASP script can do the same thing using the ObjectContext object.

© 1998 by Wrox Press. All rights reserved.