简体   繁体   English

从 .NET 访问 DB Core Web API 部署为 Azure Web App

[英]Access DB from .NET Core Web API deployed as Azure Web App

Problem :问题

We have a .NET Core Web API that we have just deployed as an Azure Web App.我们有一个 .NET 核心 Web API 我们刚刚部署为 Azure Web 应用程序。 Testing locally everything works fine, however we are unable to connect to our DB from the deployed API in Azure.在本地测试一切正常,但是我们无法从 Azure 中部署的 API 连接到我们的数据库。

From Application Insights I can see we are getting the following error:从 Application Insights 我可以看到我们收到以下错误:

Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

Our setup :我们的设置

We have our connection string included in appsettings.json我们的连接字符串包含在 appsettings.json 中

"ConnectionStrings": {
    "DefaultConnection": "Data Source=<source>.com,<port>;Initial Catalog=<db>;User ID=<username>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
},

We know our API is using this connections string because we can see in Application Insights that there is a timeout connecting to the db specified in that exact connection string.我们知道我们的 API 正在使用此连接字符串,因为我们可以在 Application Insights 中看到连接到该确切连接字符串中指定的数据库时超时。

We do not have access to DB configuration as we have read only access granted to us from a third party.我们无权访问数据库配置,因为我们拥有第三方授予的只读访问权限。 We can connect via SSMS/Azure Data Studio and when testing our Web API locally (which makes us think the connection string is correct).我们可以通过 SSMS/Azure Data Studio 连接,并在本地测试我们的 Web API(这让我们认为连接字符串是正确的)。

Other Posts we have Referenced :我们参考的其他帖子

  • Connection String in Azure Web App Configuration - I have tried including and not including our connection string from the Azure App Service Configuration - neither changed that we got a timeout and subsequent 500 error. Azure Web 应用程序配置中的连接字符串- 我尝试包括和不包括来自 Azure 应用程序服务配置的连接字符串 - 都没有改变我们得到超时和随后的 500 错误。
  • Include Connection String in appsettings.json - We have our connection string included in appsettings.json and testing locally, we can connect to the db without issue. 在 appsettings.json 中包含连接字符串- 我们将连接字符串包含在 appsettings.json 中并在本地进行测试,我们可以毫无问题地连接到数据库。
  • Improperly Formatted Connection String - The connection string works when testing locally, so we do not believe it to be an issue with the formatting of the connection string. 格式不正确的连接字符串- 连接字符串在本地测试时有效,因此我们认为这不是连接字符串格式的问题。 Additionally, because Application Insights says that there is a timeout connecting to the DB specified in the connection string, it appears to be using the connection string we are providing.此外,由于 Application Insights 表示连接到连接字符串中指定的数据库超时,它似乎正在使用我们提供的连接字符串。

Any ideas as to what might be going on here and how we can connect to the DB would be greatly appreciated.任何关于这里可能发生的事情以及我们如何连接到数据库的想法都将不胜感激。

In this case, we needed to request that the third party whitelist our Azure Web Apps Outbound IP's.在这种情况下,我们需要请求第三方将我们的 Azure Web Apps Outbound IP 列入白名单。

Your Azure Web App Outbound IP's can be located in a number of ways.可以通过多种方式找到您的 Azure Web 应用出站 IP。

Via Azure Portal通过Azure传送门

Web Apps > Your Web App > Under "Settings" go to Networking > Outbound Addresses Web Apps > 你的 Web App > 在“设置”下 go 到 Networking > Outbound Addresses

Via Azure CLI通过 Azure CLI

az webapp show -n yourwebappname -g yourresoucegroup --query "outboundIpAddresses"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何读取Service Fabric Azure App Configuration ASP.NET Core Stateless Web API? - How to read the Azure App Configuration in Service Fabric ASP.NET Core Stateless Web API? 命名信号量在 Azure App Service 上托管的 ASP.Net Core 5 Web API 上不起作用 - Named semaphore not working on ASP .Net Core 5 Web API hosted on Azure App Service azure 应用服务中的谷歌应用凭证(as.net core web api) - Google application credentials in azure app service (aspnet core web api) ASP.NET Web API 部署在 Azure 时未在应用程序洞察中记录异常 - ASP.NET Web API not logging exception in application insights when deployed in Azure ASP.NET Core 5.0 Web API 部署在应用程序服务调用第三方 API 间歇性失败并引发 500(内部服务器错误) - ASP.NET Core 5.0 Web API deployed in App service call third party API fails intermittently and raise 500 (Internal Server Error) 无法从逻辑应用执行 HTTP 后操作到 Asp.net 核心 Web API - Can't perform HTTP Post Action from Logic App to Asp.net Core Web API 在 Asp.net web 应用程序部署在 azure 应用程序服务中,获取服务(.svc)端点的 404 未找到错误 - Getting 404 not found error for service(.svc) endpoints in Asp.net web application deployed on azure app service 从ASP.NET Core访问Azure App Service ConnectionString - Access Azure App Service ConnectionString from ASP.NET Core 如何配置.NET 7 Web API部署到Azure应用服务 - How to configure .NET 7 Web API for deploying to Azure App service 部署在 azure web 应用程序上时找不到 React 应用程序上的字体 - Font on React app not found when deployed on azure web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM