title: C# Connecting with remote mysql database, getting the error “Unable to connect to any of the specified MySQL hosts”
body: <p>I was looking on many posts about this problem but not found an answer.</p>
  
  <p>I try to connect to mysql DB that exist on some server, I use with the following code from <a href="https://www.connectionstrings.com/sql-server-2014/" rel="nofollow noreferrer">https://www.connectionstrings.com/sql-server-2014/</a> and <a href="https://www.codeproject.com/Articles/43438/Connect-C-to-MySQL" rel="nofollow noreferrer">https://www.codeproject.com/Articles/43438/Connect-C-to-MySQL</a></p>
  
  <pre><code>private string server = "xx.xxx.xxx.xx";
  private string database = "testDB";
  private string username = user;
  private string password = password;
  string connectionString;
  connectionString = string.Format("Server={0},3306; Database=
  {1}; User Id={2}; password={3};", server, database, username, 
  password);
  
  connection = new MySqlConnection(connectionString);
  try
  {
      connection.Open();
  }
  catch (MySqlException ex)
  {
     return false;
  }      
  </code></pre>
  
  <p>I install MySql.Data.dll from nuget console and open the port 3306(tcp) in the server.</p>
  
  <p>When I try to open connection it gives me an error "Unable to connect to any of the specified MySQL hosts".</p>
  
  <p>Someone has an idea why?</p>
  
  <p>Thanks</p>