Features Provided by System.Transactions
This section describes how you can use the features provided by thenamespace to write your own transactional application and resource manager. Specifically, this section covers how to create and participate in a transaction (local or distributed) with one or multiple participants.
Overview of System.Transactions
The infrastructure provided by the classes in the System.Transactions namespace makes transactional programming simple and efficient by supporting transactions initiated in SQL Server, ADO.NET, Message Queuing (MSMQ), and the Microsoft Distributed Transaction Coordinator (MSDTC). The System.Transactions namespace provides both an explicit programming model based on theclass, as well as an implicit programming model using the class, in which transactions are automatically managed by the infrastructure. For more information on how to create a transactional application using these two models, see .
The System.Transactions namespace also provides types for you to implement a resource manager. A resource manager manages durable or volatile data used in a transaction, and work in cooperation with the transaction manager to provide the application with a guarantee of atomicity and isolation. The transaction manager that is provided by the System.Transactions infrastructure supports transactions involving multiple volatile resources or a single durable resource. For more information on implementing a resource manager, see.
The transaction manager also transparently escalates local transactions to distributed transactions by coordinating with a disk-based transaction manager like the DTC, when an additional durable resource manager enlists itself with a transaction. There are two key ways that the System.Transactions infrastructure provides enhanced performance.
Dynamic Escalation, which ensures that the System.Transactions infrastructure only engages the MSDTC when a transaction spans across multiple distributed resources. For more information about dynamic escalation. seetopic.
Promotable Enlistments, which allows a resource, such as a database, to take ownership of the transaction if it is the only entity participating in the transaction. Later, if needed, the System.Transactions infrastructure can still escalate the management of the transaction to the MSDTC. This further reduces the chance of using the MSDTC. Promotable Enlistments are covered in depth in the topic.
The System.Transactions namespace defines three levels of trust - AllowPartiallyTrustedCallers (APTCA), DistributedTransactionPermission(DTP) and full trust - that restrict access to the types of resources it exposes. For more information on the various trust levels, see.
In this section
Writing A Transactional Application
The System.Transactions namespace provides two models for creating transactional applications.describes how the System.Transactions namespace supports creating implicit transactions using the TransactionScope class.
describes how the System.Transactions namespace supports creating explicit transactions using the class.
For additional topics covering writing a transactional application, see.
Implementing A Resource Manager
To implement a resource manager that can participate in a transaction, see. This section covers the enlistment of a resource, committing a transaction, recovery after failure, and optimization best practices.