Exemple #1
0
            public static DbConnection GetConnection( )
            {
                Transaction trx = Transaction.Current;

                if (trx == null)
                {
                    throw new InvalidOperationException("There is no active transaction");
                }

                ConnKey key = new ConnKey(trx, _ConnectionString);

                DbConnection res;
                IDictionary <string, DbConnection> cl;

                lock ( _ConnectionList ) {
                    if (!_ConnectionList.TryGetValue(trx, out cl))
                    {
                        res = CreateConnection( );
                        cl  = new Dictionary <string, DbConnection>( );
                        cl.Add(_ConnectionString, res);
                        _ConnectionList.Add(trx, cl);
                        trx.TransactionCompleted += CleanupTransactionData;
                    }
                    else
                    {
                        if (!cl.TryGetValue(_ConnectionString, out res))
                        {
                            res = CreateConnection( );
                            cl.Add(_ConnectionString, res);
                        }
                    }
                    PrepareConnection(res);
                }
                return(res);
            }
Exemple #2
0
 public override bool Equals(object obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (obj is ConnKey)
     {
         ConnKey other = ( ConnKey )obj;
         return(other._Tran == _Tran && other._DbConn == _DbConn);
     }
     return(false);
 }