System.Transactions 命名空間

包含可用來自行撰寫交易應用程式和資源管理員的類別。 Contains classes that allow you to write your own transactional application and resource manager. 具體而言,您可以建立並參與擁有一個或多個參與者的交易 (本機或分散式)。 Specifically, you can create and participate in a transaction (local or distributed) with one or multiple participants.

類別

CommittableTransaction

描述可認可的交易。Describes a committable transaction.

DependentTransaction

描述交易的複製品 (Clone),其可保證在交易上執行工作時,必須等到應用程式停止後才能認可交易。Describes a clone of a transaction providing guarantee that the transaction cannot be committed until the application comes to rest regarding work on the transaction. 此類別無法獲得繼承。This class cannot be inherited.

DistributedTransactionPermission

當交易的管理擴大至 MSDTC 時,System.Transactions 所要求的使用權線。The permission that is demanded by System.Transactions when management of a transaction is escalated to MSDTC. 此類別無法獲得繼承。This class cannot be inherited.

DistributedTransactionPermissionAttribute

允許將 DistributedTransactionPermission 的安全性動作套用至使用宣告式安全性的程式碼。Allows security actions for DistributedTransactionPermission to be applied to code using declarative security. 此類別無法獲得繼承。This class cannot be inherited.

Enlistment

在交易的最後階段,協助登記的交易參與者與交易管理員之間的通訊。Facilitates communication between an enlisted transaction participant and the transaction manager during the final phase of the transaction.

PreparingEnlistment

在交易的準備階段,協助登記的交易參與者與交易管理員之間的通訊。Facilitates communication between an enlisted transaction participant and the transaction manager during the Prepare phase of the transaction.

SinglePhaseEnlistment

提供一組回呼,在收到 SinglePhaseCommit(SinglePhaseEnlistment) 告知時,用來協助登記於單一階段交易認可之參與者和交易管理員之間的通訊。Provides a set of callbacks that facilitate communication between a participant enlisted for Single Phase Commit and the transaction manager when the SinglePhaseCommit(SinglePhaseEnlistment) notification is received.

SubordinateTransaction

表示可以委派的非根交易。Represents a non-rooted transaction that can be delegated. 此類別無法獲得繼承。This class cannot be inherited.

Transaction

表示交易。Represents a transaction.

TransactionAbortedException

嘗試在已經復原的交易上執行作業時,或是嘗試認可交易而交易中止時,所擲回的例外狀況。The exception that is thrown when an operation is attempted on a transaction that has already been rolled back, or an attempt is made to commit the transaction and the transaction aborts.

TransactionEventArgs

提供下列交易事件的資料:DistributedTransactionStartedTransactionCompletedProvides data for the following transaction events: DistributedTransactionStarted, TransactionCompleted.

TransactionException

當您嘗試在無法接受新工作的交易上執行工作時,所擲回的例外狀況。The exception that is thrown when you attempt to do work on a transaction that cannot accept new work.

TransactionInDoubtException

嘗試在不確定的交易上執行作業時,或是嘗試認可交易而交易成為 InDoubt 時,所擲回的例外狀況。The exception that is thrown when an operation is attempted on a transaction that is in doubt, or an attempt is made to commit the transaction and the transaction becomes InDoubt.

TransactionInformation

提供有關交易的其他資訊。Provides additional information regarding a transaction.

TransactionInterop

加強 System.Transactions 與元件之間的互動,這些元件是在先前所寫入,以便與 MSDTC、COM+ 或 System.EnterpriseServices 互動。Facilitates interaction between System.Transactions and components that were previously written to interact with MSDTC, COM+, or System.EnterpriseServices. 此類別無法獲得繼承。This class cannot be inherited.

TransactionManager

包含用於交易管理的方法。Contains methods used for transaction management. 此類別無法獲得繼承。This class cannot be inherited.

TransactionManagerCommunicationException

當資源管理員無法與交易管理員通訊時,所擲回的例外狀況。The exception that is thrown when a resource manager cannot communicate with the transaction manager.

TransactionPromotionException

提升失敗時擲回的例外狀況。The exception that is thrown when a promotion fails.

TransactionScope

使程式碼區塊成為異動式。Makes a code block transactional. 此類別無法獲得繼承。This class cannot be inherited.

結構

TransactionOptions

包含指定交易行為的其他資訊。Contains additional information that specifies transaction behaviors.

介面

IDtcTransaction

描述 DTC 交易。Describes a DTC transaction.

IEnlistmentNotification

描述資源管理員應該實作的介面,可提供兩階段認可告知回呼,讓交易管理員用來登記參與。Describes an interface that a resource manager should implement to provide two phase commit notification callbacks for the transaction manager upon enlisting for participation.

IPromotableSinglePhaseNotification

描述物件,該物件用來當做資源管理員內部之非分散式交易的認可委派。Describes an object that acts as a commit delegate for a non-distributed transaction internal to a resource manager.

ISimpleTransactionSuperior

表示不是根交易,但可擴大以便由 MSDTC 管理的交易。Represents a transaction that is not a root transaction, but can be escalated to be managed by the MSDTC.

ISinglePhaseNotification

描述一個資源物件,其支援參與交易的單一階段交易認可最佳化。Describes a resource object that supports single phase commit optimization to participate in a transaction.

ITransactionPromoter

描述現有交易之已委派交易,其可在需要時擴大以由 MSDTC 管理。Describes a delegated transaction for an existing transaction that can be escalated to be managed by the MSDTC when needed.

列舉

DependentCloneOption

控制要建立何種相依交易。Controls what kind of dependent transaction to create.

EnlistmentOptions

判斷是否應該在準備階段登記物件。Determines whether the object should be enlisted during the prepare phase.

EnterpriseServicesInteropOption

指定分散式交易如何與 COM+ 交易互動。Specifies how distributed transactions interact with COM+ transactions.

IsolationLevel

指定交易的隔離等級 (Isolation Level)。Specifies the isolation level of a transaction.

TransactionScopeAsyncFlowOption

指定 TransactionScope 是否啟用跨執行緒接續的異動流程。Specifies whether transaction flow across thread continuations is enabled for TransactionScope.

TransactionScopeOption

提供建立交易範圍的其他選項。Provides additional options for creating a transaction scope.

TransactionStatus

描述分散式交易的目前狀態。Describes the current status of a distributed transaction.

委派

HostCurrentTransactionCallback

提供一個機制,讓裝載環境提供自己的 Current 預設概念。Provides a mechanism for the hosting environment to supply its own default notion of Current.

TransactionCompletedEventHandler

表示處理 TransactionCompleted 類別之 Transaction 事件的方法。Represents the method that handles the TransactionCompleted event of a Transaction class.

TransactionStartedEventHandler

表示處理 DistributedTransactionStarted 類別的 TransactionManager 事件的方法。Represents the method that will handle the DistributedTransactionStarted event of a TransactionManager class.

備註

System.Transactions基礎結構可支援在 SQL Server、ADO.NET、MSMQ 和 Microsoft Distributed Transaction Coordinator (MSDTC) 中起始的交易,以簡化整個平臺的交易程式設計。The System.Transactions infrastructure makes transactional programming simple and efficient throughout the platform by supporting transactions initiated in SQL Server, ADO.NET, MSMQ, and the Microsoft Distributed Transaction Coordinator (MSDTC). 它同時提供以類別為基礎的明確程式設計模型 Transaction ,以及使用類別的隱含程式設計模型 TransactionScope ,其中的交易會由基礎結構自動管理。It provides both an explicit programming model based on the Transaction class, as well as an implicit programming model using the TransactionScope class, in which transactions are automatically managed by the infrastructure. 強烈建議您使用更簡單的隱含模型來進行開發。It is highly recommended that you use the easier implicit model for development. 若要開始使用,請參閱 使用交易範圍執行隱含交易 主題。To get started, see the Implementing An Implicit Transaction Using Transaction Scope topic. 如需撰寫交易式應用程式的詳細資訊,請參閱 撰寫交易式應用程式For more information on writing a transactional application, see Writing A Transactional Application.

System.Transactions 也提供可讓您執行資源管理員的類型。System.Transactions also provides types for you to implement a resource manager. 基礎結構的交易管理員可 System.Transactions 讓變動性資源或單一持久資源登記有效率地認可或復原。The transaction manager native to the System.Transactions infrastructure allows volatile resources or a single durable resource enlistment to commit or roll back efficiently. 如需有關如何執行資源管理員的詳細資訊,請參閱 執行 Resource ManagerFor more information on implementing a resource manager, see Implementing A Resource Manager.

交易管理員也會透過以磁片為基礎的交易管理員(例如 DTC)進行協調,以明確地將本機交易呈報至分散式交易。當額外的永久性資源管理員自行登記交易時。The transaction manager also transparently escalates local transactions to distributed transactions by coordinating through a disk-based transaction manager like the DTC, when an additional durable resource manager enlists itself with a transaction. System.Transactions 基礎結構提供兩個提高效能的重要方法。There are two key ways that the System.Transactions infrastructure provides enhanced performance.

  • 動態擴大,這表示 System.Transactions 基礎結構只會在交易實際需要時,才會使用 MSDTC。Dynamic Escalation, which means that the System.Transactions infrastructure only engages the MSDTC when it is actually required for a transaction. 此區域將在 交易管理擴大 主題中深入討論。This area is covered in depth in the Transaction Management Escalation topic.

  • 可提升登記,可讓資源 (例如資料庫) 取得異動的擁有權 (如果該資源是參與異動之唯一實體 (Entity) 的話)。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. 之後,如果需要, System.Transactions 基礎結構仍可將交易的管理提升至 MSDTC。Later, if needed, the System.Transactions infrastructure can still escalate the management of the transaction to MSDTC. 這會進一步減少 MSDTC 的使用。This further reduces the chance of using the MSDTC. 此區域在 使用單一階段認可和可提升單一階段通知 主題的優化深度中涵蓋。This area is covered in depth in the Optimization Using Single Phase Commit and Promotable Single Phase Notification topic.

System.Transactions 定義三個信任層級,以限制其公開的資源類型的存取權。System.Transactions defines three levels of trust that restrict access on the types of resources it exposes. 具體而言,部分信任的程式碼可以呼叫 system.string 元件,因為 它已標記 AllowPartiallyTrustedCallers 屬性 (APTCA) 。Specifically, the System.Transactions assembly can be called by partially trusted code as it has been marked with the AllowPartiallyTrustedCallers attribute (APTCA). 這個屬性基本上會移除 LinkDemand 使用權限集合的隱含 FullTrust (在每個型別的每個公開存取方法上,都會自動放置這個隱含使用權限)。This attribute essentially removes the implicit LinkDemand for the FullTrust permission set that is otherwise automatically placed on each publicly accessible method in each type. 然而,部分型別和成員仍舊需要更強勢的使用權限。However, some types and members still require stronger permissions.

以下是部分信任程式碼無法呼叫的類型和成員清單,因為它們是以下列宣告式安全性屬性裝飾:The following is a list of types and members that are not callable by partially trusted code because they are decorated with the following declarative security attribute:

PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")

EnlistDurable。System.Transactions.Transaction.EnlistDurable

System.transactions.transaction.enlistpromotablesinglephase。System.Transactions.Transaction.EnlistPromotableSinglePhase

TransactionInteropSystem.Transactions.TransactionInterop

DistributedTransactionStarted。System.Transactions.TransactionManager.DistributedTransactionStarted

HostCurrentTransactionCallback。System.Transactions.TransactionManager.HostCurrentTransactionCallback

Reenlist。System.Transactions.TransactionManager.Reenlist

RecoveryComplete。System.Transactions.TransactionManager.RecoveryComplete

EnterpriseServicesInteropOption) 的,即 Transaction. Transaction. Transaction. Transaction. 交易。 (System.Transactions.TransactionScope.TransactionScope (System.Transactions.Transaction,System.TimeSpan,System.Transactions.EnterpriseServicesInteropOption)

M:System.Transactions.TransactionScope.TransactionScope (TransactionScopeOption、TransactionOptions、、、EnterpriseServicesInteropOption) M:System.Transactions.TransactionScope.TransactionScope(System.Transactions.TransactionScopeOption,System.Transactions.TransactionOptions,System.Transactions.EnterpriseServicesInteropOption)

如需各種信任層級的詳細資訊,請參閱 存取資源的安全性信任層級For more information on the various trust levels, see Security Trust Levels in Accessing Resources.

核心開發 Technologies\Data Access\Transaction 處理 Core Development Technologies\Data Access\Transaction Processing\

如需如何使用命名空間的詳細資訊 System.Transactions ,您可以參閱檔中的「核心開發 Technologies\Data Access\Transaction 處理」一節的概念檔 交易處理 \ 。For more information on how to use the System.Transactions namespace, you can consult the conceptual documentation Transaction Processing, located under the "Core Development Technologies\Data Access\Transaction Processing\" section in the documentation. 具體而言,您可以在下列主題中找到詳細資訊。Specifically, you can find more information in the following topics.

由 System.object 提供的功能Features Provided By System.Transactions

實作資源管理員Implementing A Resource Manager