Exemplo n.º 1
0
        private void ConnectionString_Set(DbConnectionPoolKey key)
        {
            DbConnectionOptions connectionOptions = null;

            System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions);
            DbConnectionInternal connectionInternal = InnerConnection;
            bool flag = connectionInternal.AllowSetConnectionString;

            if (flag)
            {
                //try {
                // NOTE: There's a race condition with multiple threads changing
                //       ConnectionString and any thread throws an exception
                // Closed->Busy: prevent Open during set_ConnectionString
                flag = SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, connectionInternal);
                if (flag)
                {
                    _userConnectionOptions = connectionOptions;
                    _poolGroup             = poolGroup;
                    _innerConnection       = DbConnectionClosedNeverOpened.SingletonInstance;
                }
                //}
                //catch {
                //    // recover from exceptions to avoid sticking in busy state
                //    SetInnerConnectionFrom(connectionInternal, DbConnectionClosedBusy.SingletonInstance);
                //    throw;
                //}
            }
            if (!flag)
            {
                throw ADP.OpenConnectionPropertySet(ADP.ConnectionString, connectionInternal.State);
            }
        }
Exemplo n.º 2
0
        private void ConnectionString_Set(string value)
        {
            System.Data.Common.DbConnectionOptions         userConnectionOptions = null;
            System.Data.ProviderBase.DbConnectionPoolGroup group           = this.ConnectionFactory.GetConnectionPoolGroup(value, null, ref userConnectionOptions);
            System.Data.ProviderBase.DbConnectionInternal  innerConnection = this.InnerConnection;
            bool allowSetConnectionString = innerConnection.AllowSetConnectionString;

            if (allowSetConnectionString)
            {
                allowSetConnectionString = this.SetInnerConnectionFrom(System.Data.ProviderBase.DbConnectionClosedBusy.SingletonInstance, innerConnection);
                if (allowSetConnectionString)
                {
                    this._userConnectionOptions = userConnectionOptions;
                    this._poolGroup             = group;
                    this._innerConnection       = System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance;
                }
            }
            if (!allowSetConnectionString)
            {
                throw System.Data.Common.ADP.OpenConnectionPropertySet("ConnectionString", innerConnection.State);
            }
            if (Bid.TraceOn)
            {
                string str = (userConnectionOptions != null) ? userConnectionOptions.UsersConnectionStringForTrace() : "";
                Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Set|API> %d#, '%ls'\n", this.ObjectID, str);
            }
        }
Exemplo n.º 3
0
        internal override void SetConnectionPoolGroup(DbConnection outerConnection, System.Data.ProviderBase.DbConnectionPoolGroup poolGroup)
        {
            OracleConnection connection = outerConnection as OracleConnection;

            if (connection != null)
            {
                connection.PoolGroup = poolGroup;
            }
        }
Exemplo n.º 4
0
 internal void PermissionDemand()
 {
     System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = this.PoolGroup;
     System.Data.Common.DbConnectionOptions         options   = (poolGroup != null) ? poolGroup.ConnectionOptions : null;
     if ((options == null) || options.IsEmpty)
     {
         throw System.Data.Common.ADP.NoConnectionString();
     }
     this.UserConnectionOptions.DemandPermission();
 }
Exemplo n.º 5
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this._userConnectionOptions = null;
         this._poolGroup             = null;
         this.Close();
     }
     this.DisposeMe(disposing);
     base.Dispose(disposing);
 }
Exemplo n.º 6
0
        internal void PermissionDemand()
        {
            Debug.Assert(DbConnectionClosedConnecting.SingletonInstance == _innerConnection, "not connecting");
            System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = PoolGroup;
            DbConnectionOptions connectionOptions = ((null != poolGroup) ? poolGroup.ConnectionOptions : null);

            if ((null == connectionOptions) || connectionOptions.IsEmpty)
            {
                throw ADP.NoConnectionString();
            }
            DbConnectionOptions userConnectionOptions = UserConnectionOptions;

            Debug.Assert(null != userConnectionOptions, "null UserConnectionOptions");
        }
Exemplo n.º 7
0
 private void CopyFrom(OracleConnection connection)
 {
     System.Data.Common.ADP.CheckArgumentNull(connection, "connection");
     this._userConnectionOptions = connection.UserConnectionOptions;
     this._poolGroup             = connection.PoolGroup;
     if (System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
     {
         this._innerConnection = System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance;
     }
     else
     {
         this._innerConnection = System.Data.ProviderBase.DbConnectionClosedPreviouslyOpened.SingletonInstance;
     }
 }
Exemplo n.º 8
0
        private void CopyFrom(SqlConnection connection)
        {
            ADP.CheckArgumentNull(connection, "connection");
            _userConnectionOptions = connection.UserConnectionOptions;
            _poolGroup = connection.PoolGroup;

            if (DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
            {
                _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
            }
            else
            {
                _innerConnection = DbConnectionClosedPreviouslyOpened.SingletonInstance;
            }
        }
Exemplo n.º 9
0
 // Copy Constructor
 private void CopyFrom(CONNECTIONOBJECTNAME connection) { // V1.2.3300
     ADP.CheckArgumentNull(connection, "connection");
     _userConnectionOptions = connection.UserConnectionOptions;
     _poolGroup = connection.PoolGroup;
     
     // SQLBU 432115
     //  Match the original connection's behavior for whether the connection was never opened,
     //  but ensure Clone is in the closed state.
     if (DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
     {
         _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
     }
     else
     {
         _innerConnection = DbConnectionClosedPreviouslyOpened.SingletonInstance;
     }
 }
Exemplo n.º 10
0
 private void ConnectionString_Set(DbConnectionPoolKey key)
 {
     DbConnectionOptions connectionOptions = null;
     System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions);
     DbConnectionInternal connectionInternal = InnerConnection;
     bool flag = connectionInternal.AllowSetConnectionString;
     if (flag)
     {
         flag = SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, connectionInternal);
         if (flag)
         {
             _userConnectionOptions = connectionOptions;
             _poolGroup = poolGroup;
             _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
         }
     }
     if (!flag)
     {
         throw ADP.OpenConnectionPropertySet(ADP.ConnectionString, connectionInternal.State);
     }
 }
Exemplo n.º 11
0
        private void ConnectionString_Set(DbConnectionPoolKey key)
        {
            DbConnectionOptions connectionOptions = null;

            System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions);
            DbConnectionInternal connectionInternal = InnerConnection;
            bool flag = connectionInternal.AllowSetConnectionString;

            if (flag)
            {
                flag = SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, connectionInternal);
                if (flag)
                {
                    _userConnectionOptions = connectionOptions;
                    _poolGroup             = poolGroup;
                    _innerConnection       = DbConnectionClosedNeverOpened.SingletonInstance;
                }
            }
            if (!flag)
            {
                throw ADP.OpenConnectionPropertySet(nameof(ConnectionString), connectionInternal.State);
            }
        }
 internal DbMetaDataFactory GetMetaDataFactory(DbConnectionPoolGroup connectionPoolGroup, DbConnectionInternal internalConnection)
 {
     DbMetaDataFactory metaDataFactory = connectionPoolGroup.MetaDataFactory;
     if (metaDataFactory == null)
     {
         bool cacheMetaDataFactory = false;
         metaDataFactory = this.CreateMetaDataFactory(internalConnection, out cacheMetaDataFactory);
         if (cacheMetaDataFactory)
         {
             connectionPoolGroup.MetaDataFactory = metaDataFactory;
         }
     }
     return metaDataFactory;
 }
 internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup)
 {
     Bid.Trace("<prov.DbConnectionFactory.QueuePoolGroupForRelease|RES|INFO|CPOOL> %d#, poolGroup=%d#\n", this.ObjectID, poolGroup.ObjectID);
     lock (this._poolGroupsToRelease)
     {
         this._poolGroupsToRelease.Add(poolGroup);
     }
     this.PerformanceCounters.NumberOfInactiveConnectionPoolGroups.Increment();
 }
 protected internal virtual DataTable GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, string collectionName, string[] restrictions)
 {
     return factory.GetMetaDataFactory(poolGroup, this).GetSchema(outerConnection, collectionName, restrictions);
 }
 internal override void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup)
 {
     OleDbConnection connection = outerConnection as OleDbConnection;
     if (connection != null)
     {
         connection.PoolGroup = poolGroup;
     }
 }
        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);
        }
Exemplo n.º 17
0
        virtual protected internal DataTable GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, string collectionName, string[] restrictions){
            Debug.Assert(outerConnection != null,"outerConnection may not be null.");

            DbMetaDataFactory metaDataFactory = factory.GetMetaDataFactory(poolGroup, this);
            Debug.Assert(metaDataFactory != null,"metaDataFactory may not be null.");

            return metaDataFactory.GetSchema(outerConnection, collectionName,restrictions);
        }
 internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
 {
     DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
     DbConnectionPoolGroupProviderInfo providerInfo = poolGroup.ProviderInfo;
     DbConnectionInternal internal2 = this.CreateConnection(connectionOptions, providerInfo, null, owningConnection);
     if (internal2 != null)
     {
         this.PerformanceCounters.HardConnectsPerSecond.Increment();
         internal2.MakeNonPooledObject(owningConnection, this.PerformanceCounters);
     }
     Bid.Trace("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> %d#, Non-pooled database connection created.\n", this.ObjectID);
     return internal2;
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this._userConnectionOptions = null;
         this._poolGroup = null;
         this.Close();
     }
     this.DisposeMe(disposing);
     base.Dispose(disposing);
 }
Exemplo n.º 20
0
        internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, ref DbConnectionOptions userConnectionOptions)
        {
            if (ADP.IsEmpty(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;
                }

                // 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);
                    }
                }


                DbConnectionPoolGroup newConnectionPoolGroup = new DbConnectionPoolGroup(connectionOptions, key, poolOptions);
                newConnectionPoolGroup.ProviderInfo = CreateConnectionPoolGroupProviderInfo(connectionOptions);

                lock (this)
                {
                    connectionPoolGroups = _connectionPoolGroups;
                    if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup))
                    {
                        // 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);
                        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;
        }
Exemplo n.º 21
0
 protected internal override DataTable GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, string collectionName, string[] restrictions)
 {
     throw ADP.ClosedConnectionError();
 }
 private void ConnectionString_Set(string value)
 {
     System.Data.Common.DbConnectionOptions userConnectionOptions = null;
     System.Data.ProviderBase.DbConnectionPoolGroup group = this.ConnectionFactory.GetConnectionPoolGroup(value, null, ref userConnectionOptions);
     System.Data.ProviderBase.DbConnectionInternal innerConnection = this.InnerConnection;
     bool allowSetConnectionString = innerConnection.AllowSetConnectionString;
     if (allowSetConnectionString)
     {
         allowSetConnectionString = this.SetInnerConnectionFrom(System.Data.ProviderBase.DbConnectionClosedBusy.SingletonInstance, innerConnection);
         if (allowSetConnectionString)
         {
             this._userConnectionOptions = userConnectionOptions;
             this._poolGroup = group;
             this._innerConnection = System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance;
         }
     }
     if (!allowSetConnectionString)
     {
         throw System.Data.Common.ADP.OpenConnectionPropertySet("ConnectionString", innerConnection.State);
     }
     if (Bid.TraceOn)
     {
         string str = (userConnectionOptions != null) ? userConnectionOptions.UsersConnectionStringForTrace() : "";
         Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Set|API> %d#, '%ls'\n", this.ObjectID, str);
     }
 }
Exemplo n.º 23
0
        internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
        {
            Debug.Assert(null != owningConnection, "null owningConnection?");
            Debug.Assert(null != poolGroup, "null poolGroup?");

            DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
            DbConnectionPoolKey poolKey = poolGroup.PoolKey;

            DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);

            if (null != newConnection)
            {
                newConnection.MakeNonPooledObject(owningConnection);
            }
            return(newConnection);
        }
Exemplo n.º 24
0
        internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, ref DbConnectionOptions userConnectionOptions)
        {
            if (ADP.IsEmpty(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);
                }

                string expandedConnectionString = key.ConnectionString;
                if (null == userConnectionOptions)   // we only allow one expansion on the connection string

                {
                    userConnectionOptions    = connectionOptions;
                    expandedConnectionString = connectionOptions.Expand();

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

                // We don't support connection pooling on Win9x; it lacks too many of the APIs we require.
                if ((null == poolOptions) && ADP.IsWindowsNT)
                {
                    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);
                    }
                }


                DbConnectionPoolGroup newConnectionPoolGroup = new DbConnectionPoolGroup(connectionOptions, key, poolOptions);
                newConnectionPoolGroup.ProviderInfo = CreateConnectionPoolGroupProviderInfo(connectionOptions);

                lock (this) {
                    connectionPoolGroups = _connectionPoolGroups;
                    if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup))
                    {
                        // 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);
#if !MOBILE
                        PerformanceCounters.NumberOfActiveConnectionPoolGroups.Increment();
#endif
                        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);
        }
Exemplo n.º 25
0
        internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
        {
            Debug.Assert(null != owningConnection, "null owningConnection?");
            Debug.Assert(null != poolGroup, "null poolGroup?");

            DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
            DbConnectionPoolKey poolKey = poolGroup.PoolKey;

            DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);

            if (null != newConnection)
            {
#if !MOBILE
                PerformanceCounters.HardConnectsPerSecond.Increment();
#endif
                newConnection.MakeNonPooledObject(owningConnection, PerformanceCounters);
            }
            Bid.Trace("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> %d#, Non-pooled database connection created.\n", ObjectID);
            return(newConnection);
        }
 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;
 }
Exemplo n.º 27
0
 abstract internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup);
 private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
 {
     if (connectionPoolGroup.IsDisabled && (connectionPoolGroup.PoolGroupOptions != null))
     {
         Bid.Trace("<prov.DbConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> %d#, DisabledPoolGroup=%d#\n", this.ObjectID, connectionPoolGroup.ObjectID);
         DbConnectionPoolGroupOptions poolGroupOptions = connectionPoolGroup.PoolGroupOptions;
         DbConnectionOptions connectionOptions = connectionPoolGroup.ConnectionOptions;
         string connectionString = connectionOptions.UsersConnectionString(false);
         connectionPoolGroup = this.GetConnectionPoolGroup(connectionString, poolGroupOptions, ref connectionOptions);
         this.SetConnectionPoolGroup(owningObject, connectionPoolGroup);
     }
     return connectionPoolGroup.GetConnectionPool(this);
 }
Exemplo n.º 29
0
        // only created by DbConnectionPoolGroup.GetConnectionPool
        internal DbConnectionPool(
                            DbConnectionFactory connectionFactory,
                            DbConnectionPoolGroup connectionPoolGroup,
                            DbConnectionPoolIdentity identity,
                            DbConnectionPoolProviderInfo connectionPoolProviderInfo)
        {
            Debug.Assert(null != connectionPoolGroup, "null connectionPoolGroup");

            if ((null != identity) && identity.IsRestricted)
            {
                throw ADP.InternalError(ADP.InternalErrorCode.AttemptingToPoolOnRestrictedToken);
            }

            _state = State.Initializing;

            lock (s_random)
            { // Random.Next is not thread-safe
                _cleanupWait = s_random.Next(12, 24) * 10 * 1000; // 2-4 minutes in 10 sec intervals
            }

            _connectionFactory = connectionFactory;
            _connectionPoolGroup = connectionPoolGroup;
            _connectionPoolGroupOptions = connectionPoolGroup.PoolGroupOptions;
            _connectionPoolProviderInfo = connectionPoolProviderInfo;
            _identity = identity;

            _waitHandles = new PoolWaitHandles();

            _errorWait = ERROR_WAIT_DEFAULT;
            _errorTimer = null;  // No error yet.

            _objectList = new List<DbConnectionInternal>(MaxPoolSize);

            _poolCreateRequest = new WaitCallback(PoolCreateRequest); // used by CleanupCallback
            _state = State.Running;

            //_cleanupTimer & QueuePoolCreateRequest is delayed until DbConnectionPoolGroup calls
            // StartBackgroundCallbacks after pool is actually in the collection
        }
Exemplo n.º 30
0
 override protected void Dispose(bool disposing) {
     if (disposing) {
         _userConnectionOptions = null;
         _poolGroup= null;
         Close();
     }
     DisposeMe(disposing);
     base.Dispose(disposing); // notify base classes
 }
Exemplo n.º 31
0
        internal DbConnectionInternal?CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions?userOptions)
        {
            Debug.Assert(null != owningConnection, "null owningConnection?");
            Debug.Assert(null != poolGroup, "null poolGroup?");

            DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo !;
            DbConnectionPoolKey poolKey = poolGroup.PoolKey;

            DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);

            if (null != newConnection)
            {
                PerformanceCounters.HardConnectsPerSecond.Increment();
                newConnection.MakeNonPooledObject(owningConnection, PerformanceCounters);
            }
            return(newConnection);
        }
Exemplo n.º 32
0
 private void ConnectionString_Set(DbConnectionPoolKey key) {
     DbConnectionOptions connectionOptions = null;
     System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions);
     DbConnectionInternal connectionInternal = InnerConnection;
     bool flag = connectionInternal.AllowSetConnectionString;
     if (flag) {
         //try {
             // NOTE: There's a race condition with multiple threads changing
             //       ConnectionString and any thread throws an exception
             // Closed->Busy: prevent Open during set_ConnectionString
             flag = SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, connectionInternal);
             if (flag) {
                 _userConnectionOptions = connectionOptions;
                 _poolGroup = poolGroup;
                 _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
             }
         //}
         //catch {
         //    // recover from exceptions to avoid sticking in busy state
         //    SetInnerConnectionFrom(connectionInternal, DbConnectionClosedBusy.SingletonInstance);
         //    throw;
         //}
     }
     if (!flag) {
         throw ADP.OpenConnectionPropertySet(ADP.ConnectionString, connectionInternal.State);
     }
     if (Bid.TraceOn) {
         string cstr = ((null != connectionOptions) ? connectionOptions.UsersConnectionStringForTrace() : "");
         Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Set|API> %d#, '%ls'\n", ObjectID, cstr);
     }
 }
Exemplo n.º 33
0
 override protected internal DataTable GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, string collectionName, string[] restrictions) {
     throw ADP.ClosedConnectionError();
 }
Exemplo n.º 34
0
        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;
                }

                // 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);
                    }
                }


                DbConnectionPoolGroup newConnectionPoolGroup = new DbConnectionPoolGroup(connectionOptions, key, poolOptions);
                newConnectionPoolGroup.ProviderInfo = CreateConnectionPoolGroupProviderInfo(connectionOptions);

                lock (this)
                {
                    connectionPoolGroups = _connectionPoolGroups;
                    if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup))
                    {
                        // 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);
                        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 DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
        {
            DbConnectionOptions connectionOptions          = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo providerInfo = poolGroup.ProviderInfo;
            DbConnectionInternal internal2 = this.CreateConnection(connectionOptions, providerInfo, null, owningConnection);

            if (internal2 != null)
            {
                this.PerformanceCounters.HardConnectsPerSecond.Increment();
                internal2.MakeNonPooledObject(owningConnection, this.PerformanceCounters);
            }
            Bid.Trace("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> %d#, Non-pooled database connection created.\n", this.ObjectID);
            return(internal2);
        }
 private void CopyFrom(OracleConnection connection)
 {
     System.Data.Common.ADP.CheckArgumentNull(connection, "connection");
     this._userConnectionOptions = connection.UserConnectionOptions;
     this._poolGroup = connection.PoolGroup;
     if (System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
     {
         this._innerConnection = System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance;
     }
     else
     {
         this._innerConnection = System.Data.ProviderBase.DbConnectionClosedPreviouslyOpened.SingletonInstance;
     }
 }
Exemplo n.º 37
0
 abstract internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup);
Exemplo n.º 38
0
        private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
        {
            // if poolgroup is disabled, it will be replaced with a new entry

            Debug.Assert(null != owningObject, "null owningObject?");
            Debug.Assert(null != connectionPoolGroup, "null connectionPoolGroup?");

            // It is possible that while the outer connection object has
            // been sitting around in a closed and unused state in some long
            // running app, the pruner may have come along and remove this
            // the pool entry from the master list.  If we were to use a
            // pool entry in this state, we would create "unmanaged" pools,
            // which would be bad.  To avoid this problem, we automagically
            // re-create the pool entry whenever it's disabled.

            // however, don't rebuild connectionOptions if no pooling is involved - let new connections do that work
            if (connectionPoolGroup.IsDisabled && (null != connectionPoolGroup.PoolGroupOptions))
            {
                // reusing existing pool option in case user originally used SetConnectionPoolOptions
                DbConnectionPoolGroupOptions poolOptions = connectionPoolGroup.PoolGroupOptions;

                // get the string to hash on again
                DbConnectionOptions connectionOptions = connectionPoolGroup.ConnectionOptions;
                Debug.Assert(null != connectionOptions, "prevent expansion of connectionString");

                connectionPoolGroup = GetConnectionPoolGroup(connectionPoolGroup.PoolKey, poolOptions, ref connectionOptions);
                Debug.Assert(null != connectionPoolGroup, "null connectionPoolGroup?");
                SetConnectionPoolGroup(owningObject, connectionPoolGroup);
            }
            DbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this);
            return connectionPool;
        }
        internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) {
            Debug.Assert(null != owningConnection, "null owningConnection?");
            Debug.Assert(null != poolGroup, "null poolGroup?");

            DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
            DbConnectionPoolKey poolKey = poolGroup.PoolKey;

            DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);
            if (null != newConnection) {
                PerformanceCounters.HardConnectsPerSecond.Increment();
                newConnection.MakeNonPooledObject(owningConnection, PerformanceCounters);
            }
            Bid.Trace("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> %d#, Non-pooled database connection created.\n", ObjectID);
            return newConnection;
        }
Exemplo n.º 40
0
        internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup)
        {
            Debug.Assert(null != poolGroup, "null poolGroup?");

            lock (_poolGroupsToRelease)
            {
                _poolGroupsToRelease.Add(poolGroup);
            }
        }
        internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key,  DbConnectionPoolGroupOptions poolOptions, ref DbConnectionOptions userConnectionOptions) {
            if (ADP.IsEmpty(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);
                }

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

                    userConnectionOptions = connectionOptions;
                    expandedConnectionString = connectionOptions.Expand();

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

                // We don't support connection pooling on Win9x; it lacks too many of the APIs we require.
                if ((null == poolOptions) && ADP.IsWindowsNT) {
                    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);
                    }
                }


                DbConnectionPoolGroup newConnectionPoolGroup = new DbConnectionPoolGroup(connectionOptions, key, poolOptions);
                newConnectionPoolGroup.ProviderInfo = CreateConnectionPoolGroupProviderInfo(connectionOptions);

                lock (this) {
                    connectionPoolGroups = _connectionPoolGroups;
                    if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup)) {
                        // 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);
                        PerformanceCounters.NumberOfActiveConnectionPoolGroups.Increment();
                        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;
        }
Exemplo n.º 42
0
        internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
        {
            Debug.Assert(null != owningConnection, "null owningConnection?");
            Debug.Assert(null != poolGroup, "null poolGroup?");

            DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
            DbConnectionPoolKey poolKey = poolGroup.PoolKey;

            DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);
            if (null != newConnection)
            {
                newConnection.MakeNonPooledObject(owningConnection);
            }
            return newConnection;
        }
        internal DbMetaDataFactory GetMetaDataFactory(DbConnectionPoolGroup connectionPoolGroup,DbConnectionInternal internalConnection){
            Debug.Assert (connectionPoolGroup != null, "connectionPoolGroup may not be null.");

            // get the matadatafactory from the pool entry. If it does not already have one
            // create one and save it on the pool entry
            DbMetaDataFactory metaDataFactory = connectionPoolGroup.MetaDataFactory;

            // consider serializing this so we don't construct multiple metadata factories
            // if two threads happen to hit this at the same time.  One will be GC'd
            if (metaDataFactory == null){
                bool allowCache = false;
                metaDataFactory = CreateMetaDataFactory(internalConnection, out allowCache);
                if (allowCache) {
                    connectionPoolGroup.MetaDataFactory = metaDataFactory;
                }
            }
            return metaDataFactory;
        }
 override internal void SetConnectionPoolGroup(DbConnection outerConnection, DbConnectionPoolGroup poolGroup) {
     SqlConnection c = (outerConnection as SqlConnection);
     if (null != c) {
         c.PoolGroup = poolGroup;
     }
 }
        internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup) {
            Debug.Assert (null != poolGroup, "null poolGroup?");
            Bid.Trace("<prov.DbConnectionFactory.QueuePoolGroupForRelease|RES|INFO|CPOOL> %d#, poolGroup=%d#\n", ObjectID, poolGroup.ObjectID);

            lock (_poolGroupsToRelease) {
                _poolGroupsToRelease.Add(poolGroup);
            }
            PerformanceCounters.NumberOfInactiveConnectionPoolGroups.Increment();
        }