Forced Abort

Overview

ASP makes it easy for you to gain the reliability provided by MTS services. You only need to include the @TRANSACTION directive in your script. This directive tells MTS that any changes that occur in that page, such as database manipulation and MSMQ message transmission, should be considered transactions. A change that is being managed by transaction services can be either committed, making it more or less permanent, or aborted, which would result in the state of the database or queue being rolled back to before the changes were made.

Code Tour

In this sample, the entire page has been declared a transaction, as just described. The sample provides some scripting commands for two other procedures that are called to perform additional completion or clean-up tasks. OnTransactionCommit is called when either the script has successfully completed, or the ObjectContext.SetComplete method has been called. Likewise, OnTransactionAbort is called when the script either encounters some kind of processing error, or the ObjectContext.SetAbort method has been called.

This sample aborts automatically by calling the ObjectContext.SetAbort method. Since the directive declared the script to be a transaction, aborting automatically rolls back changes made in the script, of which there are none, and triggers the OnTransactionAbort procedure, which prints a message.

Important   The @TRANSACTION directive must be on the first line of the .asp file, or an error will be generated.

Location

The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\transactional\SetAbort_VBScript.asp and ...\asp\transactional\SetAbort_JScript.asp.