public override void Open() { if (HasDelegatedTransaction) { throw new InvalidOperationException(Res.GetString("ADP_ConnectionNotEnlisted")); } Open(false); if (IsEnlisted && (Transaction)null != System.Transactions.Transaction.Current) { try { Enlist(System.Transactions.Transaction.Current); SqlCeDelegatedTransaction delegatedTransaction = DelegatedTransaction; for (int i = 0; i < weakReferenceCache.Count; i++) { object @object = weakReferenceCache.GetObject(i); if (@object is SqlCeCommand) { ((SqlCeCommand)@object).Transaction = delegatedTransaction.SqlCeTransaction; } } } catch { Close(); throw; } } }
public override void EnlistTransaction(Transaction SysTrans) { if ((Transaction)null == SysTrans) { string message = string.Format(CultureInfo.InvariantCulture, "SysTrans"); throw new NullReferenceException(message); } if (IsEnlisted) { if (Transaction != null) { throw new InvalidOperationException(Res.GetString("ADP_LocalTransactionPresent")); } if (DelegatedTransaction == null && ConnectionState.Open == State) { Enlist(SysTrans); SqlCeDelegatedTransaction delegatedTransaction = DelegatedTransaction; for (int i = 0; i < weakReferenceCache.Count; i++) { object @object = weakReferenceCache.GetObject(i); if (@object is SqlCeCommand) { ((SqlCeCommand)@object).Transaction = delegatedTransaction.SqlCeTransaction; } } } else if (!HasDelegatedTransaction || !(SysTrans == DelegatedTransaction.Transaction)) { throw new InvalidOperationException(Res.GetString("ADP_ConnectionNotEnlisted")); } } }
internal void Enlist(Transaction tx) { if ((Transaction)null == tx) { string message = string.Format(CultureInfo.InvariantCulture, "transaction"); throw new NullReferenceException(message); } SqlCeDelegatedTransaction sqlCeDelegatedTransaction = new SqlCeDelegatedTransaction(this, tx); if (tx.EnlistPromotableSinglePhase(sqlCeDelegatedTransaction)) { _delegatedTransaction = sqlCeDelegatedTransaction; return; } throw new InvalidOperationException(Res.GetString("ADP_ConnectionNotEnlisted")); }