gpt4 book ai didi

.net - 使用 Windows Azure 托管的连接问题

转载 作者:行者123 更新时间:2023-12-03 06:05:11 25 4
gpt4 key购买 nike

当我从 ASP.NET MVC 应用程序连接到 SQL Azure 时,出现以下错误。

Exception Details: System.Data.SqlClient.SqlException: 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)

但是,我能够从 SQL Server Management Studio 成功连接到 SQL Azure。我还尝试使用 sqlCMD 连接,并且连接没有任何问题。唯一出现的问题是在运行时出现此异常。

最佳答案

您的连接字符串肯定有问题。您无法通过命名管道连接到 Windows Azure SQL 数据库(也称为 SQL Azure)。唯一支持的协议(protocol)是 TCP。所以你的 conn 字符串看起来像这样:

Server=tcp:[servername].database.windows.net,1433;Database=[db_name];User ID=[username]@[servername];Password=[password];Trusted_Connection=False;Encrypt=True;Connection Timeout=30

您可以从管理门户获取连接字符串。当您转到数据库时,右侧会显示连接字符串链接(新门户):

SQL Azure show connection strings (new portal)

和旧的传送门几乎一样:

SQL Azure Connection Strings old portal

最后,您必须在防火墙规则中启用“允许其他 Windows Azure 服务连接到此服务器”。

**** 根据下面的评论更新 ****

这个连接字符串条目在哪里?在 web.config 中,或在 web.release.config/web.debug.config 中。请注意,web.config 转换在开发时不起作用,仅在打包时起作用!这个错误是本地调试的时候出现的,还是部署的时候出现的?

如果在本地,您可以检查您实际使用的连接字符串吗?

请注意,有默认的“ApplicationServices”连接字符串(位于 apphost.config 中),当您尝试在默认 MVC 应用程序中“登录/注册”时可能会发生这种情况!该连接字符串假定本地 SQL Express 实例存在并正在运行。这是成员(member)身份和角色提供者的默认连接字符串。除非您更改成员(member)资格提供商设置,否则您将无法登录/注册以及任何需要身份验证的操作。

关于.net - 使用 Windows Azure 托管的连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11464886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com