Share via


About Transactions and COM+ Services

A transaction isan operation that succeeds or fails as a whole. Transaction processing is used to update databases reliably. When you are making many related changes to a database or updating several databases at once, you want to ensure that all of the changes are correctly executed. If any of the changes fail, you want to restore the original state of the database tables.

Without Component Services, you would have to write your scripts and components to manually track the requested changes and restore data if any changes failed. With Component Services, you simply declare your scripts and components to require transactions and let Component Services handle the transaction coordination. Transaction processing applies only to database access; Component Services cannot roll back changes to the file system or changes to other, non-transactional resources. The database your application accesses must be supported by Component Services. Currently Component Services supports SQL Server and any database that supports the XA protocol from the X/Open consortium. Component Services will continue to expand its support for other databases in the future.

Using the Server.Transfer and Server.Execute methods a transaction can span multiple ASP pages. If a script contains the @TRANSACTION directive, with the value specified as Required, and the script is called by either the Server.Transfer or Server.Execute method, then the script will continue the transaction of the calling .asp file if the calling .asp file was transacted. If the calling .asp file was not transacted, the called .asp file will then automatically create a new transaction.

For example, the following script initiates a transaction:

  <%@ TRANSACTION=Required %>

<%
  .
  .
  . 
  'End transaction.
  Server.Transfer("/BookSales/EndTrans.asp")        
%>

However, following script calls another script that also initializes a transaction:

  <%@ TRANSACTION=Required%>

<%
  'Instantiate a custom component to close transactions.
  Set objSale = Server.CreateObject("SalesTransacted.Complete")
  .
  .
  .
%>

However, the interaction between the two scripts would constitute only a single transaction. For more information about writing scripts with Server.Transfer and Server.Execute, see Sending Content to the Browser.