sql server 跨服务器查询数据

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

其中DB表明另外一个库。sql

 

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

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

因而想有没有直接访问的办法。因而查了资料:服务器

 

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

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

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.

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

exec sp_configure 'show advanced options',1
reconfigure 
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
相关文章
相关标签/搜索