我拥有一个Azure试用账户,其中包含一个SQL数据库和一个ASP.NET 5 Web应用程序。数据库服务器防火墙已经设置了我的本地计算机IP的规则,并勾选了“允许访问Azure服务”的复选框。我可以从本地的Sql Server Manager连接到Azure数据库而没有任何问题。
Web应用程序在其“应用程序设置/连接字符串”部分设置了此连接字符串。我已经检查过该Web应用程序正在使用此连接字符串:
"Server=tcp:[MyServerName].database.windows.net,1433;Database=[MyDbName];User ID=[MyUserName]@[MyServerName];Password=[MyPassword];Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
这个相同的连接字符串在桌面客户端中也被使用并且正常工作。然而,Web应用程序无法连接到服务器,并抛出了这个异常,它很清楚,但我不知道如何解决。
"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应用程序在其“应用程序设置/连接字符串”部分设置了此连接字符串。我已经检查过该Web应用程序正在使用此连接字符串:
"Server=tcp:[MyServerName].database.windows.net,1433;Database=[MyDbName];User ID=[MyUserName]@[MyServerName];Password=[MyPassword];Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
这个相同的连接字符串在桌面客户端中也被使用并且正常工作。然而,Web应用程序无法连接到服务器,并抛出了这个异常,它很清楚,但我不知道如何解决。
"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)"
我知道这里已经有很多类似的问题被问答过了,但是它们都不是我正在面临的确切问题,也没有解决方案适用于我。
感谢大家花时间。
更新1
作为测试,我已经将网站配置在我的本地IIS上,与Azure DB配合运行,它也可以正常工作。因此,桌面应用程序、SQL Server Manager和IIS都可以从我的本地计算机访问此数据库。当然,在服务器防火墙中我的IP地址已经被加入白名单,但Azure应用服务也已经被加入白名单,但没有访问权限。
更新2
Joe Raio的评论促使我仔细检查了地区配置,并附上了当前设置的截图。我相信一切都是正确的。