我试图让一对空间启用的表在不创建递归循环的情况下相互更新。我在本地和远程服务器上都有触发器,当有更新,插入或删除时触发,因为我需要处理稍微不同的每个操作。
到目前为止,我已经尝试过了......
begin try
drop trigger sde.PolygonDeleteTrigger
end try
Begin catch
end catch
GO
CREATE TRIGGER sde.PolygonDeleteTrigger
ON sde.Polygons
AFTER DELETE
AS
BEGIN
declare @GUID nvarchar(max), -- GUGUID
@sqlString nvarchar(max)
set @GUID = (select GUID from deleted )
insert into openquery(remoteServer,'select GUID,TimeStamp from myDB.dbo._PolygonTriggerStatus')
values(@GUID,getDate())
if (select count(GUID) from sde._PolygonTriggerStatus where GUID = @GUID) = 0
BEGIN
set @sqlString = 'delete from openquery(remoteServer, ''select GUID from myDB.dbo.Polygons where GUID = ''''' + @GUID + ''''' '' )'
print @sqlString
execute sp_sqlexec @sqlString
END
set @sqlString = 'delete from openquery(remoteServer,''select GUID,TimeStamp from myDB.dbo._PolygonTriggerStatus where GUID = ''''' + @GUID + ''''' '' )'
print @sqlString
execute sp_sqlexec @sqlString
END
GO
结果是我收到错误消息:另一个会话正在使用的事务上下文。
我认为添加触发器状态表可以通过防止插入,更新和删除查询在存在相关记录的GUID(GlobalID)时更改记录来缓解此问题。我仍然得到另一个会话使用的消息"事务上下文。"
到目前为止,我还没有找到任何防止远程服务器上的触发器被触发的好方法。
有什么想法?
SQL Server:2008 Express r2