Search code examples
c#linqstored-proceduresunhandled

Linq to sql unhandled exception from update stored procedure


I have a simple Linq dbml class, containing 1 table. First I have it configured to "Use runtime" to do the updates. Throgh the UI, I'm intentionally updating a column to a wrong value. Then calling dataContext.SubmitChanges throws an error, which is caught in a catch=block, showing a MessageBox "The UPDATE statement conflicted with the CHECK constraint ...", as it should. So, everything is fine.

Then I change the update behaviour to "Customize" and use a simple update stored procedure (just 1 simple update statement). Updating through the UI with correct values works like a charm. The update sproc is called and everything is fine. But when entering this wrong value through the UI, and then pressing update, I get an unhandled exception on this line of code (internal code of the Linq class):

IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), field1, field2, ...);

Title: Exception User-Unhandled System.Data.SqlClient.SqlException: 'The UPDATE statement conflicted with the CHECK constraint "CK_tblRitCentraal". The conflict occurred in database "RCS", table "dbo.tblRitCentraal", column 'RitOpmerkingen'.

The statement has been terminated.'

Any help is greatly appreciated!


Solution

  • thanks for your reply. You are right, that my problem is, that the exception in yhe second case is not caught, even though it is exactly the same error as in the first case.

    In the meantime I solved my problem. All I had to do was tick "do not break on this type of exceptions". Now the exception is nicely put through to the UI, and I can take care of it.

    Still, I can't understand why. But hey, it got solved, so I shouldn't complain.