In this tip, Scot Hillier discusses the use of transactional Web pages, script based solutions that have the same advantages as component-based. Read more of Scot's thoughts at InformIT.
One of ASP's most interesting new features is full support for transactional Web pages. Transactional Web pages enable developers to create complete COM+ applications for the Web without the use of components. Transactional Web pages began under IIS 4 but finally reach their true potential under IIS 5. It's now possible to create solutions that have many of the same advantages of component-based solutions but that are written completely in script.
Understanding Transactional Attributes
The key to creating transactional Web pages lies in a special COM+ application named IIS Utilities. This application contains the four ASP ObjectContext components. Each component corresponds to a different transactional attribute.
The secret to starting a transaction in an ASP page is to use the @TRANSACTION directive. This directive is analogous to the transaction properties that you set for a COM+ component in an application. The @TRANSACTION directive is always placed as the first line in any ASP page; otherwise, an error is generated. When you use the directive, the operations performed in any page are treated as a unit and function in much the same way as work performed by a conventional COM+ component. The @TRANSACTION directive has the following values:
- @TRANSACTION=REQUIRES_NEW-The ASP page will always initiate a new transaction. This new transaction can enlist other ASP pages if those pages also support transactions.
- @TRANSCTION=REQUIRED-The ASP page will initiate a new transaction if one doesn't already exist. However, it might participate in transactions started by other pages.
- @TRANSACTION=NOT_SUPPORTED-The ASP page never initiates a transaction. This is the default for all ASP pages that don't specify an @TRANSACTION directive.
- @TRANSACTION=SUPPORTED-The ASP page can participate in transactions started by other pages. However, if no transaction exists, a new one won't be started.
A Simple Transaction Template
<%@Transaction="REQUIRES_NEW" Language="VBSCRIPT" %> <%Option Explicit%> <HTML> <HEAD> </HEAD> <BODY> <% 'Perform Work 'Database Operation #1 'Database Operation #2 Sub OnTransactionCommit Response.Write "<H1>Success!</H1></BODY></HTML>" End Sub Sub OnTransactionAbort Response.Write "<H1>Failure!</H1></BODY></HTML>" End Sub %>
To learn more about Transactional Web pages visit InformIT. Registration is required, but it is free.
This was first published in February 2001