SQL Server 2008:对具有触发器的表执行 MERGE 命令会导致错误
我有一个存储过程,它使用 MERGE 命令将 dbo.tableA 与 [mylinkedserver].dbo.TableA 同步。
TableA
有一个与之关联的插入/更新触发器。为了让事情变得非常简单,触发器所做的就是
print 'I am a simple trigger because i dont want to cause errors'
当执行 SP 时(通过 .net windows 应用程序),它会抛出以下错误:
链接服务器“MyLinkedServer”的 OLE DB 提供程序“SQLNCLI10” 返回消息“没有交易 活跃。”
并再次执行存储过程,它执行得绝对正常。
如果我通过 SSMS 运行存储过程,它也可以正常运行(使用触发器)。
两台服务器上都启用了 MSDTC。
服务器是 Windows 2008 服务器, SQL Server 2008 with service pack 2。
为什么触发器会导致此错误?!?!?
I have a stored procedure that uses the MERGE
command to synchronize dbo.tableA
with [mylinkedserver].dbo.TableA
.
TableA
has an insert/update trigger associated with it. To keep things really simple all the trigger does is
print 'I am a simple trigger because i dont want to cause errors'
When the SP is executed (thru a .net windows application), it throws this error:
OLE DB provider "SQLNCLI10" for linked server "MyLinkedServer"
returned message "No transaction is
active."
If I delete the trigger and execute the stored proc again, it executes absolutely fine.
The stored procedure also runs fine (with the trigger) if i run it through SSMS.
MSDTC is enabled on both servers.
Server is Windows 2008 server, SQL Server 2008 with service pack 2.
Why would a trigger cause this error ?!?!??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Merge 实现触发器有点棘手。它归结为“对于合并语句中指定的每个操作都必须有一个触发器”。
TechNet 表示:“如果目标表为 MERGE 语句执行的插入、更新或删除操作定义了启用的 INSTEAD OF 触发器,那么它必须为 MERGE 语句中指定的所有操作启用 INSTEAD OF 触发器”。
http://technet.microsoft.com/en-us/library/bb510625.aspx
Trigger implementation with Merge is a little tricky. It boils down to "for each action specified in the merge statement there must be a trigger".
TechNet Says "If the target table has an enabled INSTEAD OF trigger defined on it for an insert, update, or delete action performed by a MERGE statement, then it must have an enabled INSTEAD OF trigger for all of the actions specified in the MERGE statement."
http://technet.microsoft.com/en-us/library/bb510625.aspx