0

I recently replaced an on-prem MySQL server with Azure Database for MySQL. I have a .NET 6 C# application and it works when connected to the on-prem, but has a problem with the Azure DB. Both databases are version 5.7.32.

When the app is connected to the Azure DB, all of the SQL queries work except for one. That one SQL query throws the error shown below. The query is pretty ugly and has a lot of joins and nested selects, but it works with the on-prem. I can get the query to work if I remove some of the joins.

Is there anything else I can do to troubleshoot this or get a better understanding of what the problem is? Right now, it looks like I have to refactor the query, but I really would like more detail on what the problem was.

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Fatal error encountered during command execution.
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at XXXX.cs:line XXXX

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
MySqlException: Fatal error encountered attempting to read the resultset.

Inner Exception 2:
MySqlException: Reading from the stream has failed.

Inner Exception 3:
IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..

Inner Exception 4:
SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
user3075978
  • 775
  • 1
  • 8
  • 30
  • It seems you cannot reach the database. Check if your connection string is correct. – jalepi Mar 30 '22 at 21:33
  • It could be a server-side timeout, or it could be this longstanding MySql.Data bug: https://bugs.mysql.com/bug.php?id=76597. You might get better diagnostics by switching to MySqlConnector: https://mysqlconnector.net/tutorials/migrating-from-connector-net/ – Bradley Grainger Mar 31 '22 at 04:32
  • All of the other queries from the app work, so I don't think it is a connection string issue. The problematic query always works with the on-prem, but always fails with the Azure DB. I'm guessing that the Azure Database for MySQL handles the query differently. I might try switching to the MySqlConnector. – user3075978 Mar 31 '22 at 12:53
  • 1
    Thanks @BradleyGrainger. The MySqlConnector did have better diagnostics. It said it was a timeout error, which makes sense. Problem has been fixed. – user3075978 Apr 03 '22 at 20:55

0 Answers0