1

我在处理更新操作的视图上有一个触发器。当我使用 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 捕获错误。

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

4

0 回答 0