无法使用 Visual Studio 访问 Azure SQL 数据库,但可以使用 SSMS
Can't access Azure SQL database with Visual Studio but can with SSMS
我正在尝试从我在 Visual Studio 中构建的函数应用程序连接到托管在 Azure 上的 SQL 数据库,但出现以下错误:
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 - An attempt was made to access a socket in a way
forbidden by its access permissions.)
我可以毫无问题地使用 SSMS 从同一台 PC 进行连接。我试过在 VS 的服务器资源管理器中使用数据连接来连接到数据库,但我遇到了同样的错误。如果我在服务器资源管理器中使用我的帐户连接到 Azure,它会显示一系列服务,包括 SQL 数据库,但下面列出了 none,尽管我的帐户确实可以访问数据库。
是否有我遗漏的隐藏陷阱或 VS 中的设置?我也试过在防火墙设置中添加我的客户端 IP,但这也没有什么不同。
错误消息指出“验证实例名称是否正确”
一旦您说它是 Azure 数据库,SSMS 可能会自动创建一个完全限定的名称。
如果您使用 Visual Studio 中的短名称,则无法连接到 SQL 服务器。
例如“myserver.database.windows.net”与“myserver”。
在进行更多测试后,结果证明是客户端防火墙阻止了 VS 和 VS Code 连接到 Azure SQL。似乎已经有 SSMS 的例外。
我正在尝试从我在 Visual Studio 中构建的函数应用程序连接到托管在 Azure 上的 SQL 数据库,但出现以下错误:
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 - An attempt was made to access a socket in a way forbidden by its access permissions.)
我可以毫无问题地使用 SSMS 从同一台 PC 进行连接。我试过在 VS 的服务器资源管理器中使用数据连接来连接到数据库,但我遇到了同样的错误。如果我在服务器资源管理器中使用我的帐户连接到 Azure,它会显示一系列服务,包括 SQL 数据库,但下面列出了 none,尽管我的帐户确实可以访问数据库。
是否有我遗漏的隐藏陷阱或 VS 中的设置?我也试过在防火墙设置中添加我的客户端 IP,但这也没有什么不同。
错误消息指出“验证实例名称是否正确”
一旦您说它是 Azure 数据库,SSMS 可能会自动创建一个完全限定的名称。
如果您使用 Visual Studio 中的短名称,则无法连接到 SQL 服务器。
例如“myserver.database.windows.net”与“myserver”。
在进行更多测试后,结果证明是客户端防火墙阻止了 VS 和 VS Code 连接到 Azure SQL。似乎已经有 SSMS 的例外。