Azure Web 应用无法访问 Azure DB [英] Azure web app can't access azure DB

查看:15
本文介绍了Azure Web 应用无法访问 Azure DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 sql 数据库和 asp.net 5 Web 应用程序的 Azure 试用帐户.数据库服务器防火墙对我的本地计算机 IP 有一个规则,并且选中了允许访问 Azure 服务"复选框.我可以从我的本地 Sql Server 管理器连接到 Azure 数据库而不会发生意外.

I have an Azure trial account with an sql database and an asp.net 5 web app. The db server firewall has a rule for my local computer IP, and also the checkbox "Allow access to Azure service" on. I can connect from my local Sql Server Manager to the azure database without incident.

Web 应用程序在其应用程序设置/连接字符串"部分设置了此连接字符串.我已经使用此连接字符串检查了 wep 应用程序 IS:

The web app has this connection string set up in its 'Application Settings/Connection strings' section. I'have checked the wep app IS using this connection string:

"Server=tcp:[MyServerName].database.windows.net,1433;Database=[MyDbName];用户 ID=[MyUserName]@[MyServerName];Password=[MyPassword];Encrypt=True;TrustServerCertificate=False;联系超时=30;"

"Server=tcp:[MyServerName].database.windows.net,1433;Database=[MyDbName];User ID=[MyUserName]@[MyServerName];Password=[MyPassword];Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

在桌面客户端中使用相同的连接字符串并且工作正常.但是web应用无法连接到服务器,抛出这个异常,很清楚,但是不知道怎么解决.

This same connection string is used in a desktop client and works fine. However, the web app is unable to connect to the server, and throws this exception, which is pretty clear, but I don't know how to solve.

发生网络相关或特定于实例的错误,同时建立与 SQL Server 的连接.找不到服务器或无法访问.验证实例名称是否正确,并且SQL Server 配置为允许远程连接.(提供者:命名Pipes Provider,错误:40 - 无法打开与 SQL Server 的连接)

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)

我知道这里已经提出并回答了非常相似的问题,但它们都不是我面临的完全相同的问题,也不是我的解决方案.

I know very similar questions have been asked and answered here, but none of them are the exact same problem I'm facing, neither have been a solution for me.

感谢大家的宝贵时间.

更新 1

作为测试,我已将网站配置为在本地 IIS 上运行,针对 azure DB,它也可以运行.因此,桌面应用程序、sql server manager 和 IIS 可以从我的本地计算机访问这个数据库.当然,我的 IP 在服务器防火墙中被列入白名单,但 azure 应用服务也被列入白名单,无法访问.

As a test, I've configured the website to run on my local IIS, against the azure DB, and it works also. So, desktop applications, sql server manager and IIS can access this database from my local computer. Of course my IP is whitelisted in the server firewall, but azure app services are whitelisted also and don't have access.

更新 2

Joe Raio 的评论让我仔细检查了区域配置,这是当前设置的屏幕截图.我相信一切都是正确的.

Joe Raio's comment made me double check the region configuration, and here's an screenshot of the current settings. I believe everything is correct.

推荐答案

网络应用程序在其应用程序"中设置了此连接字符串设置/连接字符串部分.我已经检查了 wep 应用程序 IS使用这个连接字符串:

The web app has this connection string set up in its 'Application Settings/Connection strings' section. I'have checked the wep app IS using this connection string:

这不是您为 ASP.net 5 应用程序设置连接字符串的地方.

This is not where you set your connection string for your ASP.net 5 application.

打开你的文件appsettings.json,第一部分应该包含以下数据

Open your the file appsettings.json, the first section should contain the following data

  "Data": {
    "DefaultConnection": {
      "ConnectionString": "Server=(localdb)\mssqllocaldb;Database=aspnet5-WestEuroSODBAccess-96be0407-8bee-4c89-97e5-f6711136f106;Trusted_Connection=True;MultipleActiveResultSets=true"
    }

把你的连接字符串放在那里.类似的

Place your connection string in there. Similar to this

  "Data": {
    "DefaultConnection": {
      "ConnectionString": "Server=tcp:[MyServerName].database.windows.net,1433;Database=[MyDbName];User ID=[MyUserName]@[MyServerName];Password=[MyPassword];Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
    }

这将解决问题.我最初没有发现您将其设置为 ASP.net 5 应用程序.

That will resolve the issue. I did not catch originally that you were setting this up as an ASP.net 5 application.

可在此处找到其他信息:http://docs.asp.net/en/latest/fundamentals/configuration.html

Additional information can be found here: http://docs.asp.net/en/latest/fundamentals/configuration.html

这篇关于Azure Web 应用无法访问 Azure DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆