SqlConnection.EnlistDistributedTransaction(ITransaction) 方法
定义
在指定的事务中登记为分布式事务。Enlists in the specified transaction as a distributed transaction.
public:
void EnlistDistributedTransaction(System::EnterpriseServices::ITransaction ^ transaction);
public void EnlistDistributedTransaction (System.EnterpriseServices.ITransaction transaction);
member this.EnlistDistributedTransaction : System.EnterpriseServices.ITransaction -> unit
Public Sub EnlistDistributedTransaction (transaction As ITransaction)
参数
- transaction
- ITransaction
对用于登记的现有 ITransaction 的引用。A reference to an existing ITransaction in which to enlist.
注解
您可以使用 EnlistTransaction 方法在分布式事务中登记。You can use the EnlistTransaction method to enlist in a distributed transaction. 由于它在实例中登记连接 Transaction , EnlistTransaction 利用命名空间中的可用功能 System.Transactions 来管理分布式事务,使其更适合用于此目的。Because it enlists a connection in a Transaction instance, EnlistTransaction takes advantage of functionality available in the System.Transactions namespace for managing distributed transactions, making it preferable to EnlistDistributedTransaction for this purpose. 有关详细信息,请参阅分布式事务。For more information, see Distributed Transactions.
如果禁用了自动登记,则可以使用 EnlistDistributedTransaction 方法继续在现有分布式事务中登记。You can continue to enlist in an existing distributed transaction using the EnlistDistributedTransaction method if auto-enlistment is disabled. 在现有分布式事务中登记可确保在提交或回滚事务后,还会提交或回滚数据源中的代码所做的修改。Enlisting in an existing distributed transaction makes sure that, if the transaction is committed or rolled back, modifications made by the code at the data source are also committed or rolled back.
EnlistDistributedTransaction 如果已使用启动了事务,则返回异常 SqlConnection BeginTransaction 。EnlistDistributedTransaction returns an exception if the SqlConnection has already started a transaction using BeginTransaction. 但是,如果事务是从数据源启动的本地事务 (例如,通过使用对象) 显式执行 BEGIN TRANSACTION 语句 SqlCommand , EnlistDistributedTransaction 将回滚本地事务,并根据请求在现有分布式事务中登记。However, if the transaction is a local transaction started at the data source (for example, by explicitly executing the BEGIN TRANSACTION statement using an SqlCommand object), EnlistDistributedTransaction rolls back the local transaction and enlists in the existing distributed transaction as requested. 你不会收到本地事务已回滚的通知,并且负责管理所有未使用启动的本地事务 BeginTransaction 。You do not receive notice that the local transaction was rolled back, and are responsible for managing any local transactions not started using BeginTransaction.