Declaring a Transactional Script

IIS 6.0

When you declare a page to be transactional, any script commands and objects used on the page are run under the same transaction context. Component Services handles the details of creating the transaction and determining whether the transaction succeeds (commits) or fails (aborts, terminates). To declare a page transactional, add the @TRANSACTION directive to the top of the page:

<%@ TRANSACTION = value %> 

For more information about the value argument, see the @TRANSACTION directive reference.

The @TRANSACTION directive must be the very first line on the page, otherwise an error is generated. You must add the directive to each page that should be run under a transaction. The current transaction ends when the script finishes processing.

Most applications only require transaction context for certain operations. For example, an airline site might use transactional scripts for ticket purchasing and seat assignments. All other scripts could be safely run without a transaction context. Because transactions should be used only for pages that need transaction processing, you cannot declare a Global.asa file as transactional.

If a transaction is terminated, Component Services rolls back any changes made to resources that support transactions. Currently, only database servers fully support transactions because this data is the most critical to enterprise applications. Component Services does not roll back changes to files on a hard disk, ASP session and application variables, or collections. You can, however, write scripts that restore variables and collections by writing transaction events, as described later in this topic. Your script can also explicitly commit or terminate a transaction if an operation such as writing data to a file fails.