title: "Unable to connect to any of the specified MySQL hosts" when connecting to MySQL database via SSH.NET tunnel in C#
body: <p>I'm trying to connect to a MySQL DB running on Ubuntu using C# and SSH.Net.</p>
  
  <p>Our MySQL DB only allows connections from a webserver and going by what I can see from the code below, the client object connects to the webserver and then I open a port to map to 3306 on the DB server. Finally the <code>MySQLConnection</code> object opens a connection to the MySQL DB.</p>
  
  <p>However I get with exception in <code>sql.Open()</code> statement:</p>
  
  <blockquote>
    <p>Unable to connect to any of the specified MySQL hosts</p>
  </blockquote>
  
  <p>I've checked other threads on the same subject and tried their suggestions, but none of them seem to help me.</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/15124040/unable-to-connect-to-any-of-the-specified-mysql-hosts">Unable to connect to any of the specified MySQL hosts</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/4655669/unable-to-connect-to-any-of-the-specified-mysql-hosts">Unable to connect to any of the specified MySQL hosts</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/10618720/unable-to-connect-to-any-of-the-specified-mysql-hosts">unable to connect to any of the specified MySQL hosts</a></p></li>
  </ul>
  
  <p>and many more.</p>
  
  <p>Here is some test code that I'm using - </p>
  
  <pre><code>var ci =
       new ConnectionInfo(
           "server", "userid", new PasswordAuthenticationMethod("userid", "userpwd"));
  using (var client = new SshClient(ci))
  {
      client.Connect();
      if (client.IsConnected) //This part works fine - I can connect to my Webserver.
      {
          //not sure if this is correct in our context.
          var local = new ForwardedPortDynamic("127.0.0.1",3306); 
          client.AddForwardedPort(local);
          try
          {
              local.Start();
          }
          catch (SocketException se)
          {
  
          }
          string connStr =
              "Server = dbserver;Port = 3306;Database = dbname;Uid = dbuserid;Pwd = dbpwd;";
          MySqlConnection sql = new MySqlConnection(connStr);
  
          try
          {
              sql.Open();
              local.Stop();
          }
          catch (MySqlException se)
          {
          }
      }
  }
  </code></pre>
  
  <p>All of the credentials I've put in my code was taken off a working MySQLWorkbench connection to the MySQL DB.</p>
  
  <p>I work exclusively in a Windows environment, so if you want me to check for something on the Ubuntu server please also tell me, if possible, how to check for it.</p>