本地表上的 AFTER INSERT 触发器插入到 Azure 表失败

问题描述 投票:0回答:2

我在本地数据库中的 SQL 表上有一个非常简单的触发器。触发器看起来像这样:

ALTER TRIGGER [dbo].[trg_UpdateAzureDB]
ON  [dbo].[my_local_table]
AFTER INSERT,DELETE,UPDATE
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here
    INSERT INTO [myazuresvr].[myazuredb].[dbo].[myazuretable]([ImageId], [PimObjectId], [Relation], [ObjectType])
    SELECT * FROM inserted
END

因此,正如您所看到的,我想要做的是将已插入到 Azure SQL 数据库表中的数据推送。但是,当我插入表时,出现以下错误:

Msg 7399, Level 16, State 1, Procedure trg_UpdateAzureDB, Line 16 [Batch Start Line 10]
The OLE DB provider "SQLNCLI11" for linked server "myazuresvr" reported an error. One or more arguments were reported invalid by the provider.
Msg 7391, Level 16, State 2, Procedure trg_UpdateAzureDB, Line 16 [Batch Start Line 10]
The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "myazuresvr" was unable to begin a distributed transaction.

服务器被定义为本地服务器内的链接服务器。

真正奇怪的是,如果我这样做:

INSERT INTO [myazuresvr].[myazuredb].[dbo].[myazuretable]([ImageId], [PimObjectId], [Relation], [ObjectType])
    SELECT * FROM [mylocaltable]

这就完成了。这似乎与我从触发器内插入 Azure 表有关...

本地SQL版本为12.0.6108 Azure 版本显示为 12.0.2000

有什么建议吗?

sql sql-server azure database-trigger
2个回答
0
投票

错误信息显示与分布式事务有关。将“启用分布式事务升级”标志设置为 false 应该可以。


0
投票

即使我已经将启用促销设置为 true,仍然遇到此问题。还有其他解决方案吗?我可以在触发器之外运行脚本而不会出现问题。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.