MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort C# (CSharp) Method

HandleTimeoutOrThreadAbort() private method

private HandleTimeoutOrThreadAbort ( Exception ex ) : void
ex System.Exception
return void
        internal void HandleTimeoutOrThreadAbort(Exception ex)
        {
            bool isFatal = false;

            if (isKillQueryConnection)
            {
                // Special connection started to cancel a query.
                // Abort will prevent recursive connection spawning
                Abort();
                if (ex is TimeoutException)
                {
                    throw new MySqlException(Resources.Timeout, true, ex);
                }
                else
                {
                    return;
                }
            }

            try
            {

                // Do a fast cancel.The reason behind small values for connection
                // and command timeout is that we do not want user to wait longer
                // after command has already expired.
                // Microsoft's SqlClient seems to be using 5 seconds timeouts 
                // here as well.
                // Read the  error packet with "interrupted" message.
                CancelQuery(5);
                driver.ResetTimeout(5000);
                if (Reader != null)
                {
                    Reader.Close();
                    Reader = null;
                }
            }
            catch (Exception ex2)
            {
                MySqlTrace.LogWarning(ServerThread, "Could not kill query, " +
                    " aborting connection. Exception was " + ex2.Message);
                Abort();
                isFatal = true;
            }
            if (ex is TimeoutException)
            {
                throw new MySqlException(Resources.Timeout, isFatal, ex);
            }
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Advances the MySqlDataReader to the next record.
        /// </summary>
        /// <returns></returns>
        public override bool Read()
        {
            if (!_isOpen)
            {
                Throw(new MySqlException("Invalid attempt to Read when reader is closed."));
            }
            if (ResultSet == null)
            {
                return(false);
            }

            try
            {
                return(ResultSet.NextRow(CommandBehavior));
            }
            catch (TimeoutException tex)
            {
                _connection.HandleTimeoutOrThreadAbort(tex);
                throw; // unreached
            }
            catch (MySqlException ex)
            {
                if (ex.IsFatal)
                {
                    _connection.Abort();
                }

                if (ex.IsQueryAborted)
                {
                    throw;
                }

                throw new MySqlException(Resources.FatalErrorDuringRead, ex);
            }
        }
All Usage Examples Of MySql.Data.MySqlClient.MySqlConnection::HandleTimeoutOrThreadAbort