Reputation: 3153
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.
Upvotes: 18
Views: 59971
Reputation: 81
Bellash's answer above worked, but in the same place there's a new toggle switch now to allow Azure Web apps and Functions to have easy access Azure SQL automatically and you don't have to set up fire walls/IP's and stuff. I did it in one click.
It's at Home/[database]/Connect with.../Visual Studio/Configure your firewall/. The toggle is called: Allow Azure services and resources to access this server. Switch it to Yes.
Upvotes: 1
Reputation: 5476
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://colinsalmcorner.com/configuring-aad-authentication-to-azure-sql-databases/
Upvotes: 5
Reputation: 962
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.
Upvotes: 24