Using Automatic Transactions
Automatic transactions simplify the programming model because they do not require that you explicitly begin a new transaction or explicitly commit or abort the transaction. However, the most significant advantage of automatic transactions is that they work in conjunction with the DTC, which allows a single transaction to span multiple distributed data sources. In a large-scale distributed application, this advantage can be significant. Although it is possible to manually control distributed transactions by programming the DTC directly, automated transactions drastically simplify the task and are designed for component-based systems. For example, it is easy to declaratively configure multiple components to perform work that comprises a single transaction.
Automatic transactions rely on the distributed transaction support features provided by COM+, and as a result, only serviced components (that is, components that are derived from the ServicedComponent class) can use automatic transactions.
To configure a class for automatic transactions:
- Derive the class from the ServicedComponent class located within the System.EnterpriseServices namespace.
- Define the transaction requirements of the class by using the Transaction attribute. The value supplied from the TransactionOption enumerated type determines how the class will be configured in the COM+ catalog. Other properties that can be established with this attribute include the transaction isolation level and time-out.
- To avoid explicitly having to vote in the transaction outcome, you can annotate methods with the AutoComplete attribute. If these methods throw an exception, the transaction will be aborted automatically. Note that you can still directly vote toward transaction outcome if required.
- For more information about COM+ automatic transactions, search for "Automatic Transactions Through COM+" within the Platform SDK documentation.
Configuring Transaction Isolation Levels
The transaction isolation level for COM+ version 1.0-that is, COM+ running on Windows 2000-is Serialized. Although this offers the highest degree of isolation, such protection comes at the cost of performance. The overall throughput of your system is reduced because the resource managers (typically databases) involved must hold both read and write locks for the duration of the transaction. During this time, all other transactions are blocked, which can have a significant impact on your application's ability to scale.
COM+ version 1.5, which ships with Microsoft Windows .NET, allows the transaction isolation level to be configured in the COM+ catalog on a per component basis. The setting associated with the root component in the transaction determines the isolation level for the transaction. In addition, internal subcomponents that are part of the same transaction stream must not have a transaction level higher than that defined by the root component. If they do, an error will result when the subcomponent is instantiated.
For .NET managed classes, the Transaction attribute supports the public Isolation property. You can use this property to declaratively specify a particular isolation level, as illustrated in the following code.
public class Account : ServicedComponent
. . .