SQL Azure:与 SQL Azure 的连接引发异常
当我从代码连接到 SQL Azure 时,出现以下错误。我能够从 SQL Server Management Studio 成功连接到 SQL Azure。
System.Data.SqlClient.SqlException:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:TCP 提供者,错误:0 - 请求的名称有效,但未找到请求类型的数据。)
我还尝试使用 sqlCMD 连接,并且连接没有任何问题。唯一出现的问题是在运行时出现此异常。
When I connect to SQL Azure from my code, I get the following error.. I am able to connect to SQL Azure from SQL Server Management Studio successfully.
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: TCP Provider, error: 0 - The requested name is valid, but no data of the requested type was found.)
I also tried connecting using sqlCMD and that connects without any issue. Only issue arises is during runtime when I get this exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能还需要检查以确保您的防火墙允许端口 1433 上的出站连接。
You might also want to check to make sure your firewall allows outbound connections on port 1433.
导致此失败的原因可能有很多,我列出了服务器上需要允许的场景和选项。
如果您在公司的网络/防火墙内使用 Sql Server Management Studio 连接 Azure SQL 实例,首先您需要检查公司的防火墙规则是否允许这样做。
在 AZURE SQL Server 上,确保您的 IP 地址位于允许列表中。
There can be numerous reasons for this failure, I am listing out the scenarios and the options that needs to be allowed on the server.
If you are connecting an Azure SQL Instance using Sql server management studio while inside you company's network/firewall, first of all you will need to check if your company's firewall rules allow that or not.
On the AZURE SQL Server, make sure your IP address is in the allowed list.
我相信您只需要在 SQL Azure 帐户的防火墙规则中勾选“允许其他 Windows Azure 服务访问此服务器”复选框(这将允许从部署的 Azure 应用程序连接到数据库服务器)。希望这有帮助。
I believe you just need to tick the checkbox "Allow other Windows Azure services to access this server" in Firewall Rules on your SQL Azure account (this will allow connecting to the db server from your deployed Azure application). Hope this helps.
如果您在此处发布连接字符串,将会很有帮助。还有一个使用 ado.net 连接到 sql azure 的示例应用程序: http:// /msdn.microsoft.com/en-us/library/windowsazure/ee336243.aspx
请务必注意 SqlConnectionStringBuilder 属性。
It would be helpful if you post your connection string here. Also a sample app on connecting to sql azure using ado.net: http://msdn.microsoft.com/en-us/library/windowsazure/ee336243.aspx
Makesure you pay attention to the SqlConnectionStringBuilder properties.