Richard A
Richard A

Reputation: 437

Azure Cloud - connecting web application to mysql database

Relatively new to azure cloud so go easy

Configuration as below on 1 x app service (running asp.net web application) 1 x azure database for mysql server

(so currently 2 resources)

enter image description here

Now whenever i put my connection string into my web app to point to the mysql database hosted on azure, it just times out, with the error below

[MySqlException: Unable to connect to any of the specified MySQL hosts.]

I have set the security to allow access to azure services as per documentation, and disabled the enforce SSL for now. I am able to connect to the database remotely from my machine, but my web app times out.

I have tried every permutation of connection string but it makes no difference. It works if i use the mysql in app but this is not a scalable solution for us.

Upvotes: 0

Views: 223

Answers (1)

Hounddog75
Hounddog75

Reputation: 75

Did you copy your connection string from Azure and plug it into your web config under the connectionstrings node? If so, did you remove the connectionstring name then re-add it? Such as:

<connectionStrings>
<remove name="conn" />
<add name="conn" connectionString="Server=localhost\SQLEXPRESS;Database=***;Trusted_Connection=True;" providerName="System.Data.SqlClient" />

This is the best practice for using a connectionstring in a webconfig file.

As well take a look at your error details. You are trying to use environment variables for connecting to the database. This won't work because you are in two different environments: the first being your web app environment and the second being the database environment. Even if you are using Azure as a host, it still won't work.

Upvotes: 1

Related Questions