sql2005数据库与sql2008数据库数据交换
有两台服务器A和B,A中安装的是sql2005的数据库,B安装的是sql2008数据库,两台服务器需要在每天进行数据同步,即A需要将B中的新数据导入,B需要将A中的新数据导入,请问各位如何实现?
[解决办法]
跨服务器复制表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 LinkServerEXEC 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