Search code examples
mysqlasp.net-mvcentity-framework-4connection-string

Issue reconnecting ASP.NET MVC app to moved MySQL database


I am maintaining an old legacy ASP.NET MVC3 web app running in Azure. The app connects to a MySQL on-prem server (version 5.1.44) which is about to die from old age... So the dba is preparing a move to a newer server and has prepared a test instance of the database. So you would think only the connection string would need to be changed, right?

Well, it appears it't not that easy. Important to know; the database is approached via Entity Framework (version 4.4.0.0). I'm using version 6.9.9.0 of the MySql.Data ADO.Net driver for MySQL. Same version for MySQL.Data.Entity. Back then, the 'database first' approach was chosen, which has given my pain on other fronts (I'm working on rewriting the data layer with code first, but it's far from ready).

And this is what I get when connecting to the new server (running MySQL 5.7.20).

[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
   MySql.Data.MySqlClient.NativeDriver.Open() +1228
   MySql.Data.MySqlClient.Driver.Open() +22
   MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +218
   MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +287
   MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +93
   MySql.Data.MySqlClient.MySqlPool.GetConnection() +65
   MySql.Data.MySqlClient.MySqlConnection.Open() +566
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +41

[EntityException: The underlying provider failed on Open.]
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +207
   System.Data.EntityClient.EntityConnection.Open() +104
   System.Data.Objects.ObjectContext.EnsureConnection() +75
   System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +41

So I'm guessing my app's dependencies aren't compatible with the newer MySQL server, but I've got little information to go on. So first, I need to know if this is indeed the case. Because when I connect to the new server from Visual Studio, the connection does not fail.

Hoping for some insight...


Solution

  • So this has been trial and error, but the issue was resolved by reverting to MySQL's default port (3306)

    Initially, the dba had made the database available through a non-standard port, which turned out to be not so great an idea. Didn't look into it deeper, so I'm not sure if it was really a firewall issue on either side.