如何将Azure Web App连接到Azure SQL数据库

时间:2022-07-03 17:24:44

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

Azure在一年前玩的时候发生了变化。

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.

我有一个Web应用程序,以及我的Azure资源组中的Sql DB。我希望我的网络应用程序从我的数据库中读取。我做了一个防火墙规则,以便我的应用程序可以从我的工作站上的数据库读取(在本地运行),这很好。但我希望我的应用程序在部署时从数据库中读取。

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?

我是否只是制作了一个sql防火墙规则,以便在托管到数据库时允许应用程序的IP地址?或者有没有办法告诉azure web应用程序和同一资源组中的数据库,它是一个安全的连接?也许他们可以在内部连接上相互通信?

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.

我认为在旧的Azure中你可以“链接”一个应用程序和一个数据库,它完成了这一点。但不确定更新的Azure中的过程是什么。

1 个解决方案

#1


14  

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.

转到Azure SQL数据库并获取连接字符串的副本。 (它没有你的密码,所以你必须在一分钟内添加它。

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

接下来,转到Web App,单击“所有设置”,然后单击“应用程序设置”。

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.

如果您创建一个新的连接字符串,请确保它与您在代码中引用的名称相同,或者您必须更改代码并重新部署。

#1


14  

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.

转到Azure SQL数据库并获取连接字符串的副本。 (它没有你的密码,所以你必须在一分钟内添加它。

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

接下来,转到Web App,单击“所有设置”,然后单击“应用程序设置”。

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.

如果您创建一个新的连接字符串,请确保它与您在代码中引用的名称相同,或者您必须更改代码并重新部署。