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?