为什么 DataAdapter 没有收到触发器抛出的错误

发布于 2024-07-29 05:32:23 字数 1145 浏览 7 评论 0原文

我在处理更新操作的视图上有一个触发器。 当我使用 MS Management Studio 并执行插入时,我收到此错误:

Msg 50000, Level 16, State 10, Procedure Trigger_TempTableAttr_Lot_UpdateDelete, Line 166
Violation of UNIQUE KEY constraint 'UK_Lot_LotAccountCode'. Cannot insert duplicate key in object 'app.Lot'.
Msg 3616, Level 16, State 1, Line 1
An error was raised during trigger execution. The batch has been aborted and the user transaction, if any, has been rolled back.

这就是我的触发器中的内容:

BEGIN TRY
    EXEC(@UpdateSQL)
END TRY
BEGIN CATCH
        SELECT 
            @ErrorMessage = ERROR_MESSAGE(),
            @ErrorSeverity = ERROR_SEVERITY(),
            @ErrorState = ERROR_STATE();
        RAISERROR (@ErrorMessage, -- Message text.
                   16, -- Severity.
                   10 -- State.
        );
        RETURN
END CATCH

CREATE TRIGGER[dbo].[Trigger_TempTableAttr_Lot_UpdateDelete] ON [dbo].[TempTableAttr_Lot]
INSTEAD OF UPDATE, INSERT, DELETE
AS
BEGIN

开头的错误永远不会发送到 DataAdapter,它会默默地失败。 我在 DataAdapter.RowUpdated 上有一个事件处理程序,但此操作没有错误。 也不会捕获 INSERT 或 DELETE 错误。

什么可能会阻止我在应用程序中收到错误?

I have a trigger on a view that handles update operations. When I use the MS Management Studio and do an insert I get this error:

Msg 50000, Level 16, State 10, Procedure Trigger_TempTableAttr_Lot_UpdateDelete, Line 166
Violation of UNIQUE KEY constraint 'UK_Lot_LotAccountCode'. Cannot insert duplicate key in object 'app.Lot'.
Msg 3616, Level 16, State 1, Line 1
An error was raised during trigger execution. The batch has been aborted and the user transaction, if any, has been rolled back.

This is what I have in my trigger:

BEGIN TRY
    EXEC(@UpdateSQL)
END TRY
BEGIN CATCH
        SELECT 
            @ErrorMessage = ERROR_MESSAGE(),
            @ErrorSeverity = ERROR_SEVERITY(),
            @ErrorState = ERROR_STATE();
        RAISERROR (@ErrorMessage, -- Message text.
                   16, -- Severity.
                   10 -- State.
        );
        RETURN
END CATCH

CREATE TRIGGER[dbo].[Trigger_TempTableAttr_Lot_UpdateDelete] ON [dbo].[TempTableAttr_Lot]
INSTEAD OF UPDATE, INSERT, DELETE
AS
BEGIN

The error at the beginning of this is never sent to the DataAdapter, it silently fails. I have an event handler on DataAdapter.RowUpdated but there is no error for this operation. No error is caught for INSERT or DELETE either.

What may be going on to prevent me from having an error received in the application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文