internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, ref DbConnectionOptions userConnectionOptions)
        {
            if (string.IsNullOrEmpty(key.ConnectionString))
            {
                return((DbConnectionPoolGroup)null);
            }

            DbConnectionPoolGroup connectionPoolGroup;
            Dictionary <DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;

            if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup) || (connectionPoolGroup.IsDisabled && (null != connectionPoolGroup.PoolGroupOptions)))
            {
                // If we can't find an entry for the connection string in
                // our collection of pool entries, then we need to create a
                // new pool entry and add it to our collection.

                DbConnectionOptions connectionOptions = CreateConnectionOptions(key.ConnectionString, userConnectionOptions);
                if (null == connectionOptions)
                {
                    throw ADP.InternalConnectionError(ADP.ConnectionError.ConnectionOptionsMissing);
                }

                if (null == userConnectionOptions)
                { // we only allow one expansion on the connection string
                    userConnectionOptions = connectionOptions;
                    string expandedConnectionString = connectionOptions.Expand();

                    // if the expanded string is same instance (default implementation), then use the already created options
                    if ((object)expandedConnectionString != (object)key.ConnectionString)
                    {
                        // CONSIDER: caching the original string to reduce future parsing
                        DbConnectionPoolKey newKey = (DbConnectionPoolKey)((ICloneable)key).Clone();
                        newKey.ConnectionString = expandedConnectionString;
                        return(GetConnectionPoolGroup(newKey, null, ref userConnectionOptions));
                    }
                }

                // We don't support connection pooling on Win9x
                if (null == poolOptions)
                {
                    if (null != connectionPoolGroup)
                    {
                        // reusing existing pool option in case user originally used SetConnectionPoolOptions
                        poolOptions = connectionPoolGroup.PoolGroupOptions;
                    }
                    else
                    {
                        // Note: may return null for non-pooled connections
                        poolOptions = CreateConnectionPoolGroupOptions(connectionOptions);
                    }
                }

                lock (this)
                {
                    connectionPoolGroups = _connectionPoolGroups;
                    if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup))
                    {
                        DbConnectionPoolGroup newConnectionPoolGroup = new DbConnectionPoolGroup(connectionOptions, key, poolOptions);
                        newConnectionPoolGroup.ProviderInfo = CreateConnectionPoolGroupProviderInfo(connectionOptions);

                        // build new dictionary with space for new connection string
                        Dictionary <DbConnectionPoolKey, DbConnectionPoolGroup> newConnectionPoolGroups = new Dictionary <DbConnectionPoolKey, DbConnectionPoolGroup>(1 + connectionPoolGroups.Count);
                        foreach (KeyValuePair <DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
                        {
                            newConnectionPoolGroups.Add(entry.Key, entry.Value);
                        }

                        // lock prevents race condition with PruneConnectionPoolGroups
                        newConnectionPoolGroups.Add(key, newConnectionPoolGroup);
                        SqlClientEventSource.Log.EnterActiveConnectionPoolGroup();
                        connectionPoolGroup   = newConnectionPoolGroup;
                        _connectionPoolGroups = newConnectionPoolGroups;
                    }
                    else
                    {
                        Debug.Assert(!connectionPoolGroup.IsDisabled, "Disabled pool entry discovered");
                    }
                }
                Debug.Assert(null != connectionPoolGroup, "how did we not create a pool entry?");
                Debug.Assert(null != userConnectionOptions, "how did we not have user connection options?");
            }
            else if (null == userConnectionOptions)
            {
                userConnectionOptions = connectionPoolGroup.ConnectionOptions;
            }
            return(connectionPoolGroup);
        }
        internal DbConnectionPoolGroup GetConnectionPoolGroup(string connectionString, DbConnectionPoolGroupOptions poolOptions, ref DbConnectionOptions userConnectionOptions)
        {
            DbConnectionPoolGroup group;

            if (ADP.IsEmpty(connectionString))
            {
                return(null);
            }
            if (!this._connectionPoolGroups.TryGetValue(connectionString, out group) || (group.IsDisabled && (group.PoolGroupOptions != null)))
            {
                DbConnectionOptions options = this.CreateConnectionOptions(connectionString, userConnectionOptions);
                if (options == null)
                {
                    throw ADP.InternalConnectionError(ADP.ConnectionError.ConnectionOptionsMissing);
                }
                string str = connectionString;
                if (userConnectionOptions == null)
                {
                    userConnectionOptions = options;
                    str = options.Expand();
                    if (str != connectionString)
                    {
                        return(this.GetConnectionPoolGroup(str, null, ref userConnectionOptions));
                    }
                }
                if ((poolOptions == null) && ADP.IsWindowsNT)
                {
                    if (group != null)
                    {
                        poolOptions = group.PoolGroupOptions;
                    }
                    else
                    {
                        poolOptions = this.CreateConnectionPoolGroupOptions(options);
                    }
                }
                DbConnectionPoolGroup group2 = new DbConnectionPoolGroup(options, poolOptions)
                {
                    ProviderInfo = this.CreateConnectionPoolGroupProviderInfo(options)
                };
                lock (this)
                {
                    Dictionary <string, DbConnectionPoolGroup> dictionary = this._connectionPoolGroups;
                    if (!dictionary.TryGetValue(str, out group))
                    {
                        Dictionary <string, DbConnectionPoolGroup> dictionary2 = new Dictionary <string, DbConnectionPoolGroup>(1 + dictionary.Count);
                        foreach (KeyValuePair <string, DbConnectionPoolGroup> pair in dictionary)
                        {
                            dictionary2.Add(pair.Key, pair.Value);
                        }
                        dictionary2.Add(str, group2);
                        this.PerformanceCounters.NumberOfActiveConnectionPoolGroups.Increment();
                        group = group2;
                        this._connectionPoolGroups = dictionary2;
                    }
                    return(group);
                }
            }
            if (userConnectionOptions == null)
            {
                userConnectionOptions = group.ConnectionOptions;
            }
            return(group);
        }