13
votes

Azure has changed a fair bit from a year ago when I played with it.

I have a web app, and a Sql DB in my Azure resource group. I want my web app to read from my DB. I made a firewall rule so that my app can read from the DB at my workstation (running locally), and that is fine. But I want my app to read from the DB when it is deployed.

Do I just make a sql firewall rule to allow the app's IP address when hosted through to the DB? Or is there a way I can tell azure that the web app, and the DB in the same resource group,and it is a secure connection? Perhaps that they could communicate with each other on an internal connection?

I think in the old Azure you could 'link' an app and a DB and it accomplished this. But not sure what the procedure is in the updated Azure.

2
There are two website where you can manage the resources in the Azure. one is portal preview and the other one is old one. Which one are you using? Also do you have both webapp and sqldb in Azure?vendettamit
Edit: it is the preview portalsheamus
Yup! this is preview portal. I think if you have both app and db in Azure then you won't be needing any firewall rules to add. But if you need to access the DB from your local machine then you need to update Add client IP in firewall settings of Sql Server in your resource group. Also after first deployment you have to add the Azure sql connection string manually in Appsettings of webApp. If you need details let me know.vendettamit

2 Answers

20
votes

Go to your Azure SQL Database and get a copy of the connection string. (It won't have your password, so you'll have to add that in a minute.

Next, go to your Web App, click on the "All Settings" and under then click "Application Settings".

Scroll down to "Connection Strings" and either create a new connection string (and paste it in from the first step) or update the existing connection string. Be sure to update the password in your connection string.

If you create a new connection string, make sure it's the same name as that one you are referencing in your code or you will have to change your code and redeploy as that as well.

2
votes

You don't need to store username / password details in the connection string with Azure Sql, you can add a token to the SqlConnection object. Here's a link to a site that details how to do it:

https://www.colinsalmcorner.com/post/configuring-aad-authentication-to-azure-sql-databases