为什么 DataAdapter 没有收到触发器抛出的错误
我在处理更新操作的视图上有一个触发器。 当我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论