我想用存储过程来同步数据库(以下是摘录):
--为了方便同步处理,创建链接服务器到要同步的服务器
--这里的远程服务器名为:xz,用户名为:sa,无密码
if exists(select 1 from master..sysservers where srvname='srv_lnk')
exec sp_dropserver 'srv_lnk','droplogins'
go
exec sp_addlinkedserver  'srv_lnk','','SQLOLEDB','afa'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'sa'
go
--创建同步处理的存储过程
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_synchro]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_synchro]
GO
create proc p_synchro
as
--set  XACT_ABORT on
--启动远程服务器的MSDTC服务
--exec master..xp_cmdshell 'isql /S"xz" /U"sa" /P"" /q"exec master..xp_cmdshell ''net start msdtc'',no_output"',no_output--启动本机的MSDTC服务
--exec master..xp_cmdshell 'net start msdtc',no_output--进行分布事务处理,如果表用标识列做主键,用下面的方法
--BEGIN DISTRIBUTED TRANSACTION
--同步删除的数据
delete from srv_lnk.test.dbo.[user]
  where id not in(select id from [user])--同步新增的数据
insert into srv_lnk.test.dbo.[user]
select id,number,name from [user] where state is null--同步修改的数据
update srv_lnk.test.dbo.[user] set
  number=b.number,name=b.name
from srv_lnk.test.dbo.[user] a
  join [user] b on a.id=b.id
where b.state=1--同步后更新本机的标志
update [user] set state=0 where isnull(state,1)=1
--COMMIT TRAN
go服务器: 消息 208,级别 16,状态 1,过程 p_synchro,行 13
对象名 'srv_lnk.test.dbo.[user]'无效。
服务器: 消息 266,级别 16,状态 1,过程 p_synchro,行 65535
EXECUTE 后的事务计数指出缺少了 COMMIT 或 ROLLBACK TRANSACTION 语句。原计数 = 0,当前计数 = 1。 我应该怎么改??