How to Connect Azure Web App to Azure SQL Database

南楼画角 提交于 2019-11-29 07:28:35

问题


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.


回答1:


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:


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



来源:https://stackoverflow.com/questions/33134034/how-to-connect-azure-web-app-to-azure-sql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!