OleDbConnection.EnlistDistributedTransaction(ITransaction) 方法


在指定的事务中登记为分布式事务。Enlists in the specified transaction as a distributed transaction.

 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)



对用于登记的现有 ITransaction 的引用。A reference to an existing ITransaction in which to enlist.


ADO.NET 2.0 中的新增项支持使用 EnlistTransaction 方法在分布式事务中登记。New in ADO.NET 2.0 is support for using 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. 有关分布式事务的详细信息,请参阅分布式事务For more information about distributed transactions, see Distributed Transactions.

如果 OleDbConnection 已使用 BeginTransaction启动了一个事务,EnlistDistributedTransaction 将返回异常。EnlistDistributedTransaction returns an exception if the OleDbConnection has already started a transaction using BeginTransaction. 但是,如果事务是从数据源启动的本地事务(例如,通过使用 OleDbCommand 对象显式执行 BEGIN TRANSACTION 语句),则 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 OleDbCommand object), EnlistDistributedTransaction rolls back the local transaction and enlists in the existing distributed transaction as requested. 你不会收到本地事务已回滚的通知,并负责管理未使用 BeginTransaction启动的任何本地事务。You won't receive notice that the local transaction was rolled back and are responsible for managing any local transactions not started using BeginTransaction.