Ping() public method

public Ping ( ) : bool
return bool
Esempio n. 1
0
 /// <summary>
 /// Ping
 /// </summary>
 /// <returns></returns>
 public bool Ping()
 {
     if (Reader != null)
     {
         Throw(new MySqlException(Resources.DataReaderOpen));
     }
     if (driver != null && driver.Ping())
     {
         return(true);
     }
     driver = null;
     SetState(ConnectionState.Closed, true);
     return(false);
 }
Esempio n. 2
0
        private Driver GetPooledConnection()
        {
            Driver driver = null;

            lock (((ICollection)this.idlePool).SyncRoot)
            {
                if (this.HasIdleConnections)
                {
                    driver = this.idlePool.Dequeue();
                }
            }
            if (driver != null)
            {
                try
                {
                    driver.ResetTimeout((int)(this.Settings.ConnectionTimeout * 1000u));
                }
                catch (Exception)
                {
                    driver.Close();
                    driver = null;
                }
            }
            if (driver != null)
            {
                if (!driver.Ping())
                {
                    driver.Close();
                    driver = null;
                }
                else
                {
                    if (this.settings.ConnectionReset)
                    {
                        driver.Reset();
                    }
                }
            }
            if (driver == null)
            {
                driver = this.CreateNewPooledConnection();
            }
            lock (((ICollection)this.inUsePool).SyncRoot)
            {
                this.inUsePool.Add(driver);
            }
            return(driver);
        }
Esempio n. 3
0
        private Driver CheckoutConnection()
        {
            Driver driver = (Driver)this.idlePool.Dequeue();

            if (!driver.Ping())
            {
                driver.Close();
                return(null);
            }
            if (this.settings.ResetPooledConnections)
            {
                driver.Reset();
            }
            this.inUsePool.Add(driver);
            return(driver);
        }
Esempio n. 4
0
        /// <summary>
        /// CheckoutConnection handles the process of pulling a driver
        /// from the idle pool, possibly resetting its state,
        /// and adding it to the in use pool.  We assume that this method is only
        /// called inside an active lock so there is no need to acquire a new lock.
        /// </summary>
        /// <returns>An idle driver object</returns>
        private Driver CheckoutConnection()
        {
            Driver driver = (Driver)idlePool.Dequeue();

            // first check to see that the server is still alive
            if (!driver.Ping())
            {
                driver.Close();
                driver = CreateNewPooledConnection();
            }

            // if the user asks us to ping/reset pooled connections
            // do so now
            if (settings.ConnectionReset)
            {
                driver.Reset();
            }

            return(driver);
        }
Esempio n. 5
0
        /// <summary>
        /// It is assumed that this method is only called from inside an active lock.
        /// </summary>
        private Driver GetPooledConnection()
        {
            Driver driver = null;

            // if we don't have an idle connection but we have room for a new
            // one, then create it here.
            lock ((idlePool as ICollection).SyncRoot)
            {
                if (HasIdleConnections)
                {
                    driver = (Driver)idlePool.Dequeue();
                }
            }

            if (driver != null)
            {
                // first check to see that the server is still alive
                if (!driver.Ping())
                {
                    driver.Close();
                    driver = null;
                }
                else if (settings.ConnectionReset)
                {
                    // if the user asks us to ping/reset pooled connections
                    // do so now
                    driver.Reset();
                }
            }
            if (driver == null)
            {
                driver = CreateNewPooledConnection();
            }

            Debug.Assert(driver != null);
            lock ((inUsePool as ICollection).SyncRoot)
            {
                inUsePool.Add(driver);
            }
            return(driver);
        }