lundi 20 juin 2016

Random connection problems from Azure C# app to remote MySQL server

I have an ASP.NET MVC web app that connects to a remote MySQL server (Ubuntu). I've never had any problems on my own Windows Server or localhost, but when I recently moved the app to Azure app services I get random connection errors:

Unable to connect to any of the specified MySQL hosts.
at MySql.Data.MySqlClient.NativeDriver.Open() 
at MySql.Data.MySqlClient.Driver.Open() 
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuildersettings)
at MySql.Data.MySqlClient.MySqlConnection.Open()

There's no inner exception. My code looks a bit like:

using(var con = new MySqlConnection(connectionString))
{
  con.Open();
  using(var cmd = CreateCommand(sql, con))
  {
    cmd.Execute();        
  }
  con.Close();
}

Connection string looks like:

server=x.x.x.x;uid=xxx;pwd=xxx;database=xxx;Connection Timeout=10;Pooling=false;Protocol=socket;Port=3306;

This topic describes the same problem:

It has nothing to do with the firewall on the Ubuntu server, when a connection fails I don't even see incoming requests in the firewall. I also tried to use other settings in the connection string. Any ideas?

Aucun commentaire:

Enregistrer un commentaire