日期:2014-05-18  浏览次数:20751 次

跨服务器插入数据
目的就是想把插入到表中的数据同步插入到另一台远程的SQL服务器上,表结构相同,我写的哪里有问题么?
SQL code

CREATE TRIGGER [nmtohrb] ON [dbo].[recfiles] 
FOR INSERT
AS
Begin
Insert into OPENDATASOURCE('SQLOLEDB','Data Source=www.baidu.com;User ID=sa;Password=XXX').aaa.dbo.recfiles select * from inserted
End



------解决方案--------------------
SQL code
--加上下面两句,否则会提示新事务不能登记到指定事务处理器
set    xact_abort   on  
begin  distributed   tran

------解决方案--------------------
SQL code

CREATE TRIGGER [nmtohrb] ON [dbo].[recfiles] 
FOR INSERT
AS
begin --少了个begin
    set xact_abort on  
    begin distributed tran
    Insert into 
    OPENDATASOURCE('SQLOLEDB','Data Source=www.baidu.com;User ID=sa;Password=XXX').aaa.dbo.recfiles 
    select * from inserted
End