4

I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have just discovered a duplicate key error when attempting a database insert. However, I had to use SQL Profiler to find the error. The insert template page just silently did nothing.

How can I trap errors like this and log them and maybe display a message?

ProfK
  • 49,207
  • 121
  • 399
  • 775

2 Answers2

2

Exceptions can be detected, if not caught, in the CUD event arguments on the DetailsView and the DataSource controls, e.g. events such as DetailsView_ItemInserted, and DetailsDataSource_Inserting have Exception Exception and bool ExceptionHandled properties for handling exceptions.

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • If you are handling the exception, make sure to set the ExceptionHandled property to True so that it responds back to the front end correctly. – StingyJack Jul 11 '13 at 21:03
0

Another approach that you could implement in Dynamic Data site is using a custom derived DynamicValidator control.

For detail information, please, refer to the link Handling database exceptions in Dynamic Data

Konstantin
  • 796
  • 1
  • 11
  • 32