日期:2014-05-18 浏览次数:20672 次
跨服务器复制表
select * INTO [SMSDB].[dbo].[SysLog]
FROM openrowset('sqloledb',‘目标服务器’;'账号';'密码',[SMSDB].[dbo].[SysLog])
(将数据库目标服务器中的SysLog表复制本地的数据库SMSDB中)
eg:如果出现以下错误:
(SQL Server 阻止了对组件 'Ad Hoc Distributed Queries'
的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组
件已作为此服务器安全配置的一部分而被关闭。系统管理员可以
通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。
有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅
SQL Server 联机丛书中的 "外围应用配置器"。)
解决方法:
启用Ad Hoc Distributed Queries: exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
使用完成后,关闭Ad Hoc Distributed Queries:exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure
------解决方案--------------------
Exec sp_droplinkedsrvlogin LinkServer,Null --若存在先刪除
Exec sp_dropserver LinkServer
EXEC sp_addlinkedserver
@server= 'LinkServer',--被訪問的服務器別名
@srvproduct= '',
@provider= 'SQLOLEDB',
@datasrc= 'IP,port' --要訪問的服務器
EXEC sp_addlinkedsrvlogin
'Server', --被訪問的服務器別名
'false ',
NULL,
'UserAccount', --帳號
'password' --密碼
查詢
select * from Server.dbname.dbo.table_name