I have a jqgrid which works fine. However there is a constraint in my database and I need to provide more meaningful validation method when adding.
The problem is when I submit the dialog shows the error: error Status: ‘error’. Error code: 500
I would much prefer it to show the actual error caused by the exception thrown on save:
Violation of UNIQUE KEY constraint ‘UKC_InvoiceId_ActivityId’. Cannot insert duplicate key in object ‘dbo.InvoiceLine’. The duplicate key value is (11, 1). The statement has been terminated.
Can anybody tell me how to achieve this?
If you use ASP.NET then you can use
try {...} catch (SqlException ex) {...}block over the code which implement the row insertion. You can analyseex.Procedure, ex.Server, ex.LineNumber, ex.Messagevalues inside of theSqlExceptionand generate (throw) another exception with more readable message. You can use in the error message the texts typed by the user and explain which data the user have to modify to solve the problem.