Syntax Error

Overview

Using ASP, you can easily take advantage of 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 or 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 purposely commits a syntax error with the nonsense command Blah.Blah. As a result of the syntax error, the script aborts, and the script's OnTransactionAbort method is called.

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\RunTimeErrorAbort_VBScript.asp and ...\asp\transactional\RunTimeErrorAbort_JScript.asp.