sql server 跨服务器查询数据

  • 面临个问题想把另一个sqlserver库中的数据导入到另一库中,之前都是统一服务器的两个子库,
select * from DB..table

其中DB代表另一个库。

  •  现在问题变了想要从另外的一个服务器上拿数据,上边的显然不行了。

之前的笨方法都是从一个库中用excel导出,在把导出的excel导入到另一个服务器。

于是想有没有直接访问的办法。于是查了资料:

select * from openrowset('sqloledb','192.168.1.18';'用户名';'密码,'select top 10 * from DB..table')

 在数据库中执行发现报错了

Msg 15281, Level 16, State 1, Line 2
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.

  就又查资料发现先执行下面这段代码就行了:

exec sp_configure 'show advanced options',1
reconfigure 
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
原文地址:https://www.cnblogs.com/zhangchenghu/p/3583966.html