title: Getting 1042 error while connecting to MySql database via SSH on remote desktop
body: <p>I can't get connected to MySql database via SSH on remote desktop. I use C# and SshNet library. Actually, I have no problem to connect to the database with the help of popular tools, such as SQL Manager Lite, but when I do the same thing with the same settings with my tool - always get</p>
  
  <blockquote>
    <p>Mysql 1042 Error (Unable to connect to any of the specified MySQL hosts)</p>
  </blockquote>
  
  <p>Also, the part in my.cnf is edited to 
      <code>bind-address = 0.0.0.0</code> and
      <code># skip-networking</code>. (Yes I tried with localhost and server ip on bind-address - same problem)</p>
  
  <p>And I also granted all permissions to the user. Double-checked that.</p>
  
  <p>Please, look at the code, maybe I missed something.</p>
  
  <p>And sorry, I'm using forms, I just will need GUI :{</p>
  
  <p>Many thanks in advance, everybody.</p>
  
  <pre class="lang-cs prettyprint-override"><code>PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo("serverip", "sshlogin", "sshpass");
          connectionInfo.Timeout = TimeSpan.FromSeconds(30);
          using (var client = new SshClient(connectionInfo))
          {
              try
              {
                  client.Connect();
                  if (client.IsConnected)
                  {
                      label1.Text = "ssh ok";
                  }
                  else
                  {
                      label1.Text = "ssh shit";
                  }
  
                  var port = new ForwardedPortRemote(3306, "serverip", 3306);
                  client.AddForwardedPort(port);
                  port.Start();
                  if (port.IsStarted)
                  {
                      label5.Text = "port open";
                  }
                  else
                  {
                      label5.Text = "port shit";
                  }
                  var conn_info = "Server=serverip;Port=3306;Database=database;Uid=remoteuser;Pwd=password;";
                  bool isConn = false;
                  MySqlConnection conn = null;
                  try
                  {
                      conn = new MySqlConnection(conn_info);
                      conn.Open();
                      isConn = true;
                  }
                  catch (ArgumentException a_ex)
                  {
  
                      label3.Text = "Check the Connection String.";
                      label4.Text = a_ex.Message;
                      label5.Text = a_ex.ToString();
  
                  }
                  catch (MySqlException ex)
                  {
                      string sqlErrorMessage = "Message: " + ex.Message + "\n" +
                      "Source: " + ex.Source + "\n" +
                      "Number: " + ex.Number;
                      label3.Text = sqlErrorMessage;
  
                      isConn = false;
                      switch (ex.Number)
                      {
                         case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
                              break;
                          case 0: // Access denied 
                              break;
                          default:
                              break;
                      }
                  }
                  finally
                  {
                      if (conn.State == ConnectionState.Open)
                      {
                          conn.Close();
                      }
                  }
                  client.Disconnect();
                  label2.Text = isConn.ToString();
              }
              catch (SocketException exd)
              {
                  label5.Text = exd.Message;
              }
  
          }
  </code></pre>