OracleConnection.EnlistDistributedTransaction(ITransaction) 方法


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

 void EnlistDistributedTransaction(System::EnterpriseServices::ITransaction ^ distributedTransaction);
public void EnlistDistributedTransaction (System.EnterpriseServices.ITransaction distributedTransaction);
member this.EnlistDistributedTransaction : System.EnterpriseServices.ITransaction -> unit
Public Sub EnlistDistributedTransaction (distributedTransaction 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 命名空间中的可用功能来管理分布式事务,使其更适合EnlistDistributedTransaction用于实现此目的。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.

你可以继续在现有分布式事务中登记,只需要使用You can continue to enlist in an existing distributed transaction using the

如果禁用自动登记,则 EnlistDistributedTransaction 方法。EnlistDistributedTransaction method if auto-enlistment is disabled. 在现有分布式事务中登记可确保在提交或回滚事务后,还会提交或回滚数据源中的代码所做的修改。Enlisting in an existing distributed transaction ensures that, if the transaction is committed or rolled back, modifications made by the code at the data source are also committed or rolled back.

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