Azure WebApp 无法与 Azure WebSql 数据库通信

Azure WebApp not able to communicate with Azure WebSql Database

场景:

Azure 上使用 WebAPI 的 webApp(不是 WebSite 或 WebService)无法连接到其 Azure 数据库。尽管我已经(暂时)打开了 0.0.0.0 - 255.255.255.255 但没有帮助,但在数据库防火墙中没有可打开的 WebApp IP。 我们收到以下一般性错误消息:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

运行 Web App 在本地连接到 Azure 数据库正常。

WebApp通过EF6连接数据库。

所以我们知道连接字符串有效,我们知道数据库可以访问并且 WebAPI 有效......只有当 WebApp 放在 Azure 上时它才会失败。

我们如何解决这个问题?

好的,解决方案比需要的复杂一点。如果不进行严重的捏造,您就无法让 webApp 与 WebSql 数据库进行通信。然而,正确但更昂贵的解决方案是:

  1. 创建 Ms SQL 数据库虚拟机。
  2. 为 API
  3. 创建一个 Ms Windows 虚拟机
  4. 创建 vNetwork 并将两个 VM 放在网络上
  5. 配置 API 使用属于 数据库虚拟机

瞧。