public static void RemoveConnection(Driver driver)
        {
            Debug.Assert(driver != null);

            MySqlPool pool = driver.Pool;

            if (pool == null)
            {
                return;
            }

            pool.RemoveConnection(driver);
        }
        /// <summary>
        /// Remove drivers that have been idle for too long.
        /// </summary>
        public static void CleanIdleConnections(object obj)
        {
            List <Driver> oldDrivers = new List <Driver>();

            lock (pools.SyncRoot)
            {
                foreach (string key in pools.Keys)
                {
                    MySqlPool pool = (pools[key] as MySqlPool);
                    oldDrivers.AddRange(pool.RemoveOldIdleConnections());
                }
            }
            foreach (Driver driver in oldDrivers)
            {
                driver.Close();
            }
        }
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string text = GetKey(settings);

            lock (pools.SyncRoot)
            {
                MySqlPool pool = (pools[text] as MySqlPool);

                if (pool == null)
                {
                    pool = new MySqlPool(settings);
                    pools.Add(text, pool);
                }
                else
                {
                    pool.Settings = settings;
                }

                return(pool);
            }
        }
        private static void ClearPoolByText(string key)
        {
            lock (pools.SyncRoot)
            {
                // if pools doesn't have it, then this pool must already have been cleared
                if (!pools.ContainsKey(key))
                {
                    return;
                }

                // add the pool to our list of pools being cleared
                MySqlPool pool = (pools[key] as MySqlPool);
                clearingPools.Add(pool);

                // now tell the pool to clear itself
                pool.Clear();

                // and then remove the pool from the active pools list
                pools.Remove(key);
            }
        }
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                throw new InvalidOperationException(ResourceStrings.ConnectionAlreadyOpen);
            }
            SetState(ConnectionState.Connecting, true);
            try
            {
                if (settings.Pooling)
                {
                    MySqlPool pool = MySqlPoolManager.GetPool(settings);
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = pool.GetConnection();
                    }
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = Driver.Create(settings);
                    }
                }
            }
            catch (Exception)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);
            if (settings.Database != null && settings.Database != String.Empty)
            {
                ChangeDatabase(settings.Database);
            }
            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
 public static void RemoveClearedPool(MySqlPool pool)
 {
     Debug.Assert(clearingPools.Contains(pool));
     clearingPools.Remove(pool);
 }
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);
            }

            SetState(ConnectionState.Connecting, true);

#if !CF
            // if we are auto enlisting in a current transaction, then we will be
            // treating the connection as pooled
            if (settings.AutoEnlist && Transaction.Current != null)
            {
                driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
                if (driver != null &&
                    (driver.IsInActiveUse ||
                     !driver.Settings.EquivalentTo(this.Settings)))
                {
                    throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);
                }
            }
#endif

            try
            {
                if (settings.Pooling)
                {
                    MySqlPool pool = MySqlPoolManager.GetPool(settings);
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = pool.GetConnection();
                    }
                    procedureCache = pool.ProcedureCache;
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = Driver.Create(settings);
                    }
                    procedureCache = new ProcedureCache((int)settings.ProcedureCacheSize);
                }
            }
            catch (Exception)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);
            if (settings.Database != null && settings.Database != String.Empty)
            {
                ChangeDatabase(settings.Database);
            }

            // setup our schema provider
            schemaProvider = new ISSchemaProvider(this);
#if !CF
            perfMonitor = new PerformanceMonitor(this);
#endif

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option
#if !MONO && !CF
            if (Transaction.Current != null && settings.AutoEnlist)
            {
                EnlistTransaction(Transaction.Current);
            }
#endif

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
 public static void RemoveClearedPool(MySqlPool pool)
 {
     Debug.Assert(clearingPools.Contains(pool));
     clearingPools.Remove(pool);
 }
        public static MySqlPool GetPool(MySqlConnectionStringBuilder settings)
        {
            string text = GetKey(settings);

            lock (pools.SyncRoot)
            {
                MySqlPool pool = (pools[text] as MySqlPool);

                if (pool == null)
                {
                    pool = new MySqlPool(settings);
                    pools.Add(text, pool);
                }
                else
                    pool.Settings = settings;

                return pool;
            }
        }