I have 3 layer architecture. When user clicks on submit button. All the value gets set into business layer. Then into the business layer a datalayer function is called to insert data into database. I have a unique field in database. When I assign a non unique value to that field it throws an exception at DataLayer.
I need to know, what is the right approach to handle these cases. Should we check it in business layer, that non unique value can’t proceed to DataAccess Layer or should we handle the exception from the Dataaccess layer. Please also let me know, how to handle such kind of exceptions and show a business message to user.
I various approaches like
Error No
Edit: To detect that sql exception is for duplicate entry you can check out Entity Framework: How to properly handle exceptions that occur due to SQL constraints and Unique Key Violation in SQL Server – Is it safe to assume Error 2627?