问题描述
在 SSMS 中,我尝试从 Azure sql 数据库的查询窗口中选择本地 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: Named Pipes Provider,error: 40 - Could not open a connection to sql Server)'.
我已经为本地 sql Server 的外部表创建了定义。表定义属性显示正确的数据源,您可以看到数据源定义:
data_source_id name location type_desc type resource_manager_location credential_id
database_name shard_map_name connection_options pushdown
65537 eternareport localhost RDBMS 1 NULL 65537 eternareport NULL NULL ON
和范围凭据:
name principal_id credential_id credential_identity create_date modify_date target_type target_id
ExternalReportingDBCredential 1 65537 sa 2020-12-14 15:32:19.983 2020-12-14 15:32:19.983 NULL NULL
对于我尝试过的本地主机、内部 ip (10.0.0.12) 和外部 IP... 添加的位置:1433、tcp://、mssql://,所有结果都相同。我在不同的数据库中创建了其他外部表,但都在 Azure sql 上,而不是 localhost。
我在 SSMS 中同时打开了 localhost 和 Azure sql 数据库,并使用 sql 身份验证访问两者。我不确定我还忘记了什么。
注意:这可能是“信任服务器证书”选项的问题吗?我似乎记得之前检查过。
解决方法
您还可以通过 Azure V-Net 引用 communicate with on-premises resources 并创建 Point-to-site VPN。以便您的 Azure SQL 外部表可以连接到您的本地 SQLServer。