Connecting to remote MySql database through NLog Core Api hosted on Azure

0

So I have a .NET Core 3.1 Web Api app (running in App Service) that connects to a MySQL database on a hosted server (no root access) using the connection string server=example.co.uk;port=3306;database=db_name;user=db_user;password=supersecretpassword.

The app itself works running locally, allows me to select, insert, and update fine using Pomelo.EntityFrameworkCore.MySql, however after publishing fails with:

System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. 
Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Connect Timeout expired.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. 

Adding EnableRetryOnFailure() simply results in a longer duration before I get the same error message. So I check the connection string and it turns out the syntax is slightly off, so changed it to Server=example.co.uk; Port=3306; Database=db_name; Uid=db_user; Pwd=supersecretpassword, but no change, and it fails with the exact same error.

The connection string, username, and password are correct, as I can access the database from my home PC (outside of hosted server). The only issues I can imagine that would exist are;

  1. The MySql instance is running on a hosted server, where I have to enter a whitelist of addresses that can access the databases. I have allowed azure.com and azurewebsites.net, so I'm not sure if that would cover all bases.

  2. I'm missing something pretty fundamental with how Azure App Services need to be set up.

Anyone have any ideas regarding this?

mysql
.net
azure
.net-core
asked on Stack Overflow Oct 14, 2020 by AranDG • edited Oct 14, 2020 by AranDG

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0