DbConnection.EnlistTransaction有什么作用? [英] What does DbConnection.EnlistTransaction do?
问题描述
DbConnection.EnlistTransaction有什么作用?
What does DbConnection.EnlistTransaction do?
推荐答案
DbConnection.EnlistTransaction
允许:
- 将连接加入
System.Transactions.交易
.它有一些限制:- 如果该连接已经在参与本地"网络,则为本地".交易(
System.Data.Common.DbTransaction
),它可能会失败并出现异常.(这似乎取决于具体的连接实现:在这种情况下,Firebird 2不会引发异常,
- Joining the connection to a
System.Transactions.Transaction
. It has some constraints:- If the connection is already participating in a "local" transaction (
System.Data.Common.DbTransaction
), it may fail with an exception. (This seems to depend on the concrete connection implementation: Firebird 2 does not throw an exception in such situation,SqlConnection
and likely most others do throw.) - If the connection was already joined to another
System.Transactions.Transaction
, and this other transaction is still active, it will fail with an exception.
DbConnection.EnlistTransaction
通常与System.Transactions.Transaction.Current
.如果在 FbConnection 低于其6.0版本),或使用其他连接字符串参数(例如DbConnection.EnlistTransaction
is usually used withSystem.Transactions.Transaction.Current
. It is not required to use it if the connection is acquired (opened) within aTransactionScope
: in such case, the connection automatically enlists itself in the current transaction (unless its connection string dictates otherwise withenlist=false
). But once again, some connection implementations may differ here too: some do not have auto-enlistment enabled by default and have a quite different semantic for it (like FbConnection prior to its 6.0 version), or do use a different connection string parameter (likeMySqlConnection
which usesAutoEnlist
).这篇关于DbConnection.EnlistTransaction有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- If the connection is already participating in a "local" transaction (
- 如果该连接已经在参与本地"网络,则为本地".交易(