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

SetState() private method

private SetState ( ConnectionState newConnectionState, bool broadcast ) : void
newConnectionState ConnectionState
broadcast bool
return void
        internal void SetState(ConnectionState newConnectionState, bool broadcast)
        {
            if (newConnectionState == connectionState && !broadcast)
                return;
            ConnectionState oldConnectionState = connectionState;
            connectionState = newConnectionState;
			if (broadcast)
				OnStateChange(new StateChangeEventArgs(oldConnectionState, connectionState));
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Advances the data reader to the next result, when reading the results of batch SQL statements.
        /// </summary>
        /// <returns></returns>
        public bool NextResult()
        {
            if (!isOpen)
            {
                throw new MySqlException("Invalid attempt to NextResult when reader is closed.");
            }

            // clear any rows that have not been read from the last rowset
            if (currentResult != null)
            {
                currentResult.Consume();
            }

            // tell our command to continue execution of the SQL batch until it its
            // another resultset
            try
            {
                CommandResult nextResult = command.GetNextResultSet(this);
                if (nextResult != null)
                {
                    currentResult = nextResult;
                }
                else
                {
                    // if there was no more resultsets, then signal done
                    canRead = false;
                    return(false);
                }
                readCount = 0;

                schemaTable = null;

                // When executing query statements, the result byte that is returned
                // from MySql is the column count.  That is why we reference the LastResult
                // property here to dimension our field array
                connection.SetState(ConnectionState.Fetching);

                // load in our field defs and set our internal variables so we know
                // what we can do (canRead, hasRows)
                canRead = hasRows = currentResult.Load();
                fields  = currentResult.Fields;
                return(true);
            }
            catch (Exception ex)
            {
                if (ex is MySqlException && !(ex as MySqlException).IsFatal)
                {
                    connection.SetState(ConnectionState.Open);
                }
                else
                {
                    connection.Terminate();
                }
                throw;
            }
            finally
            {
                if (connection.State != ConnectionState.Closed && connection.State != ConnectionState.Open)
                {
                    connection.SetState(ConnectionState.Open);
                }
            }
        }