【问题标题】:How to connect an Azure SQL Managed Instance to an Azure App Service (written in .NET Core 2.2)如何将 Azure SQL 托管实例连接到 Azure 应用服务(使用 .NET Core 2.2 编写)
【发布时间】:2020-04-06 13:24:21
【问题描述】:

我有一个 .NET Core 2.2 Web 应用程序部署到 Azure 应用程序服务,我正在连接到一个 Azure SQL 托管实例。 Appsettings.json 中要写入的连接字符串应该是什么。我尝试了在 Azure 门户中找到的以下连接字符串,但它不起作用。

"AZURESQLCONNSTR_":Server=tcp:azure-abcde.database.windows.net,1433;Persist Security Info=False;User ID=userid;Password=password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

但是当我尝试运行下面的 Azure 应用服务时,我没有得到任何数据。

http://productwebapp.azurewebsites.net/api/ProductDetails/GetProductDetails.

您能否提出解决此问题的方法?

【问题讨论】:

标签: azure connection-string azure-app-service-envrmnt azure-sql-managed-instance


【解决方案1】:

您必须允许某些 IP 地址连接到它。查看 SQL 数据库服务器的防火墙设置。您可以通过您计算机的 IP 地址(或 IP 范围)来访问 SQL 数据库

确保启用允许 Azure 服务和资源访问服务器

编辑:

关注资源

Create an Azure SQL Database managed instance

Connect an Azure App Service hosted application

【讨论】:

  • @Sajeetharan- 当我使用 VM 和创建托管实例时提供的默认电源 shell 脚本将数据库部署到托管实例时,如何配置这些 IP。
  • 对不起,这不是正确的答案,请查看链接docs.microsoft.com/bs-latn-ba/azure/sql-database/…
  • @Sajeetharan- 我将端口 9000,9003,1438,1440,1452 添加到 Jumpbox 的 NSG 并再次部署应用程序,但仍然无法正常工作。
  • 尝试从本地机器连接并查看
【解决方案2】:

正如您所说,您已将 .NET Core 2.2 Web 应用程序部署到 Azure 应用服务,您希望连接到 Azure SQL 托管实例。

您的 Web 应用是 Azure App Service 宿主应用程序。

我想你可以参考这个教程:Connect an Azure App Service hosted application:

只能通过私有 IP 地址访问托管实例,因此要从 Azure 应用服务访问它,您首先需要在应用程序和托管实例 VNet 之间建立连接。见Integrate your app with an Azure Virtual Network

有关疑难解答,请参阅Troubleshooting VNets and Applications。如果无法建立连接,请尝试synching the networking configuration

将 Azure 应用服务连接到托管实例的一种特殊情况是将 Azure 应用服务集成到与托管实例 VNet 对等的网络。这种情况需要设置以下配置:

  • 托管实例 VNet 不得有网关
  • 托管实例 VNet 必须设置使用远程网关选项
  • 对等 VNet 必须设置允许网关传输选项

另一个参考:https://docs.microsoft.com/bs-latn-ba/azure/sql-database/sql-database-connect-query-dotnet-core

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2022-07-27
    • 1970-01-01
    • 2023-03-06
    • 2017-06-29
    • 2019-06-08
    • 2020-01-08
    • 1970-01-01
    • 2020-04-07
    • 2021-01-26
    相关资源
    最近更新 更多