/// <summary> /// You should never call this directly, the providers call this method. /// </summary> /// <param name="cmd">The command to enlist into a transaction</param> /// <param name="connectionString">The connection string passed to the CreateIDbConnectionDelegate delegate</param> /// <param name="creator">The delegate previously registered by the provider</param> static public void Enlist(IDbCommand cmd, string connectionString, CreateIDbConnectionDelegate creator) { esTransactionScope currentTx = GetCurrentTx(); if (currentTx == null || currentTx.option == esTransactionScopeOption.Suppress) { cmd.Connection = creator(); cmd.Connection.ConnectionString = connectionString; cmd.Connection.Open(); } else { Transaction tx = null; if (currentTx.root.transactions.ContainsKey(connectionString)) { tx = currentTx.root.transactions[connectionString] as Transaction; } else { tx = new Transaction(); IDbConnection cn = creator(); cn.ConnectionString = connectionString; cn.Open(); // The .NET framework has a bug in that the IDbTransaction only maintains // a weak reference to the Connection, thus, we put a strong reference // on it. tx.sqlCn = cn; if (_isolationLevel != IsolationLevel.Unspecified) { tx.sqlTx = cn.BeginTransaction(_isolationLevel); } else { tx.sqlTx = cn.BeginTransaction(); } currentTx.root.transactions[connectionString] = tx; } cmd.Connection = tx.sqlTx.Connection; cmd.Transaction = tx.sqlTx; } }