Basic Transaction

Overview

Using ASP, you can easily take advantage of the reliability provided by Component Services. To do so you only need to include the @TRANSACTION directive in your script. This directive tells Component Services that any changes occurring in the page, such as database manipulation or Message Queuing message transmission, should be considered transactions. A change that is being managed by transaction services can either be committed which would make the change permanent, or aborted the latter would result in the database or queue being rolled back to its previous state, before the changes were made.

Code Tour

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

This sample commits by default, since it simply prints a small message and then exits. Since the directive declared the script to be a transaction, exiting successfully automatically commits changes made in the script (although in this case there are none), and triggers the OnTransactionCommit 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\SimpleTransaction_VBScript.asp and ...\asp\transactional\SimpleTransaction_JScript.asp.