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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值