Getting Started
  Introduction
  What is ASP.NET?
  Language Support

ASP.NET Web Forms
  Introducing Web Forms
  Working with Server Controls
  Applying Styles to Controls
  Server Control Form Validation
  Web Forms User Controls
  Data Binding Server Controls
  Server-Side Data Access
  Data Access and Customization
  Working with Business Objects
  Authoring Custom Controls
  Web Forms Controls Reference
  Web Forms Syntax Reference

ASP.NET Web Services
  Introducing Web Services
  Writing a Simple Web Service
  Web Service Type Marshalling
  Using Data in Web Services
  Using Objects and Intrinsics
  The WebService Behavior
  HTML Pattern Matching

ASP.NET Web Applications
  Application Overview
  Using the Global.asax File
  Managing Application State
  HttpHandlers and Factories

Cache Services
  Caching Overview
  Page Output Caching
  Page Fragment Caching
  Page Data Caching

Configuration
  Configuration Overview
  Configuration File Format
  Retrieving Configuration

Deployment
  Deploying Applications
  Using the Process Model
  Handling Errors

Security
  Security Overview
  Authentication & Authorization
  Windows-based Authentication
  Forms-based Authentication
  Authorizing Users and Roles
  User Account Impersonation
  Security and WebServices

Localization
  Internationalization Overview
  Setting Culture and Encoding
  Localizing ASP.NET Applications
  Working with Resource Files

Tracing
  Tracing Overview
  Trace Logging to Page Output
  Application-level Trace Logging

Debugging
  The SDK Debugger

Performance
  Performance Overview
  Performance Tuning Tips
  Measuring Performance

ASP to ASP.NET Migration
  Migration Overview
  Syntax and Semantics
  Language Compatibility
  COM Interoperability
  Transactions

Sample Applications
  A Personalized Portal
  An E-Commerce Storefront
  A Class Browser Application
  IBuySpy.com

  Get URL for this page

MTS Transactions

A transaction is an operation or set of operations that succeeds or fails as a logical unit. A good example of a transaction is the transfer of funds from one bank account to another. In this case, the funds must be debited from the first account and credited to the second account before the operation can be considered a success. If the funds are successfully debited but not credited, the debit from the first account must be undone to leave both accounts in a correct and consistent state.

Transactions are normally managed by declaring boundaries around a set of operations. Operations that execute in the context of the transaction boundary then succeed or fail as a unit. For ASP.NET, the transaction boundary is the execution of a single request to a page, which might contain nested components that participate in the same transaction. While the page is executing, if an operation on the page itself or a nested component in the same transaction fails, it can call ContextUtil.SetAbort. This is then picked up by the current transaction context, the entire transaction fails, and any operations that were already completed are undone. If nothing fails, the transaction is committed.

ASP.NET support for transactions consists of the ability to allow pages to participate in ongoing Microsoft .NET Framework transactions. Transaction support is exposed via an @Transaction directive that indicates the desired level of support:

<%@ Transaction="Required" %>

The following table defines the supported transaction attributes. The absence of a transaction directive is the same as an explicit directive to "Disabled". Unlike ASP, ASP.NET has no explicit directive for none (that is, Transaction="None").

AttributeDescription
Required The page requires a transaction. It runs in the context of an existing transaction, if one exists. If not, it starts one.
RequiresNew The page requires a transaction and a new transaction is started for each request.
Supported The page runs in the context of an existing transaction, if one exists. If not, it runs without a transaction.
NotSupported The page does not run within the scope of transactions. When a request is processed, its object context is created without a transaction, regardless of whether there is an active transaction.

A transaction can be explicitly committed or aborted using static methods of the System.EnterpriseServices.ContextUtil class. You can explicitly call the SetComplete or SetAbort method to commit or abort an ongoing transaction.

Note: A transaction will commit or abort at the end of page's lifetime depending on the whether SetComplete or SetAbort was called last, provided there is no other object join the same transaction.


' Try to do something crucial to transaction completing.
If (Not DoSomeWork())
    ContextUtil.SetAbort()
End If
VB

Section Summary

  1. A transaction is an operation or set of operations that succeeds or fails as a logical unit.
  2. ASP.NET transaction support consists of the ability to allow pages to participate in ongoing Microsoft .NET Framework transactions. Transaction support is exposed via an @Transaction directive that indicates the desired level of support.
  3. A transaction can be explicitly committed or aborted using static methods of the System.EnterpriseServices.ContextUtil class. Developers can explicitly call the SetComplete or SetAbort method to commit or abort an ongoing transaction.


Copyright 2001 Microsoft Corporation. All rights reserved.

GoToMyPC | ASP.NET Knowledge Base