private void CheckState()
{
// There must be a valid and open connection.
if (connection == null)
throw new InvalidOperationException("Connection must be valid and open.");
if (connection.State != ConnectionState.Open && !connection.SoftClosed)
throw new InvalidOperationException("Connection must be valid and open.");
// Data readers have to be closed first
if (connection.Reader != null)
throw new MySqlException("There is already an open DataReader associated with this Connection which must be closed first.");
}