title: C# - Unable to connect to any of the specified MySQL hosts
body: <p>I'm creating a system in C# and MySQL, but I keep getting this frustrating error, "Unable to connect to any of the specified MySQL hosts". I've tried many different things but nothing has worked, could someone PLEASE try to help me?</p>
  
  <pre><code>public bool tryLogin(string username, string password)
      {
          MySqlConnection con = new MySqlConnection("host=hostremoved;user=user_removed;password=passwordremoved;database=databaseremoved;");
          MySqlCommand cmd = new MySqlCommand("SELECT * FROM login WHERE user_name = '" + username + "' AND user_pass = '" + password + "';");
          cmd.Connection = con;
          con.Open();
          MySqlDataReader reader = cmd.ExecuteReader();
          if (reader.Read() != false)
          {
  
              if (reader.IsDBNull(0) == true)
              {
                  cmd.Connection.Close();
                  reader.Dispose();
                  cmd.Dispose();
                  return false;
              }
              else
              {
                  cmd.Connection.Close();
                  reader.Dispose();
                  cmd.Dispose();
                  return true;
              }
          }
          else
          {
              return false;
          }
      }
  
      private void btnlogin_Click(object sender, EventArgs e)
      {
          if (tryLogin(txtuser.Text, txtpass.Text) == true)
          {
              MessageBox.Show("Login worked!");
          }
          else
          {
              MessageBox.Show("Login failed!");
  </code></pre>