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
相關文章
相關標籤/搜索