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