[英]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 :我们参考的其他帖子:
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.