Connecting web api to MySQL in app.

EmielD 1 Reputation point
2022-04-13T21:34:20.363+00:00

Hello,

I'm using a web API for a project where I'm working on, the problem is, when i try to connect to the MySQL In app I get this error:

One or more errors occurred. (An attempt was made to access a socket in a way forbidden by its access permissions.)

I got the connection string from the MYSQLCONNSTR_localdb.ini file.

It looks like this: Database=localdb;Data Source=127.0.0.1;User Id=azure;Password=password

I am using the MySql.Data package to connect.

I'm pretty new to azure, this is just something I need to do for my project. I hope I could get some help. Thanks in advance!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,187 questions
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
714 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,686 Reputation points
    2022-04-13T21:44:25.933+00:00

    that connect string is for a local MySql server (same server as the website). If you deploy to azure, MySql will not be on the same server, nor will it be able to access your local MySql.

    You will need to create a MySql instance in azure, and use its connect string.

    https://learn.microsoft.com/en-us/azure/mysql/quickstart-create-mysql-server-database-using-azure-portal


  2. Bruce (SqlWork.com) 56,686 Reputation points
    2022-04-14T17:55:37.767+00:00

    not sure what you are saying. MySql is service that is installed. on your dev box, you installed asp.net core and MySql. unless you are using an azure virtual machine, you need a MySql instance for you website to access. to access the MySql on you dev box, you would need to install virtual vpn routing software so an azure website could connect to you dev box. this is probably more expensive than a MySql instance.

    with your student account, you could also use a serverless managed Azure Sqlserver instance. this is probably cheaper.

    0 comments No comments