0

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 (sometimes it works, sometimes not):

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?

Community
  • 1
  • 1
Marthijn
  • 3,292
  • 2
  • 31
  • 48

1 Answers1

0

protocol=socket tells your dot net instance to try to connect to a local MySQL server with UNIX domain sockets. But you're obviously trying to connect to a remote server with TCP/IP. Omitting protocol=socket from your connection string may help.

Does your Ubuntu server have a host name? If so, use it in place of an IP address. Is the IP route from Azure to your Ubuntu server stable, or does it go up and down? What happens if you ping your Ubuntu server from your Azure host?

A note: consider using tls (ssl) for this connection. The MySQL protocol without tls is not very secure.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Thanks for your reply, I will try your suggestions. I used a hostname before, but changed it to IP to make sure it wasn't a DNS problem. – Marthijn Jun 20 '16 at 06:33