System.Transactions Namespace

System.Transactions 命名空間包含可用來自行撰寫交易應用程式和資源管理員的類別。 The System.Transactions namespace 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.Transactions可由部分信任程式碼呼叫組件,因為它已標示與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")

System.Transactions.Transaction.EnlistDurableSystem.Transactions.Transaction.EnlistDurable

System.Transactions.Transaction.EnlistPromotableSinglePhaseSystem.Transactions.Transaction.EnlistPromotableSinglePhase

System.Transactions.TransactionInteropSystem.Transactions.TransactionInterop

System.Transactions.TransactionManager.DistributedTransactionStartedSystem.Transactions.TransactionManager.DistributedTransactionStarted

System.Transactions.TransactionManager.HostCurrentTransactionCallbackSystem.Transactions.TransactionManager.HostCurrentTransactionCallback

System.Transactions.TransactionManager.ReenlistSystem.Transactions.TransactionManager.Reenlist

System.Transactions.TransactionManager.RecoveryCompleteSystem.Transactions.TransactionManager.RecoveryComplete

System.Transactions.TransactionScope.TransactionScope (System.Transactions.Transaction,System.TimeSpan,System.Transactions.EnterpriseServicesInteropOption)System.Transactions.TransactionScope.TransactionScope (System.Transactions.Transaction,System.TimeSpan,System.Transactions.EnterpriseServicesInteropOption)

M:System.Transactions.TransactionScope.TransactionScope(System.Transactions.TransactionScopeOption,System.Transactions.TransactionOptions,System.Transactions.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.

核心開發技術 Access\Transaction Processing\Core Development Technologies\Data Access\Transaction Processing\

如需有關如何使用System.Transactions命名空間中,您可以查閱概念文件交易處理下 「 核心開發技術 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.Transactions 所提供的功能Features Provided By System.Transactions

實作資源管理員Implementing A Resource Manager