I am working on my first real asp.net web application, and I am a little fixated on the best place and method to catch and handle database restriction violations. Suppose I have a unique constraint for a column, and the user enters something that violates this unique constraint. Do I grab it at the business level by contacting the database to check if a value exists for this column, or can I let it completely go through the database path and give it an exception and handle it in my application?
I don't like the last answer because it makes sense to process as much as you can at the business level before it reaches the database. But this is also somewhat problematic, since my application is controlled by procedures that implement basic CRUD operations for all tables. Therefore, in order for me to ensure the uniqueness of the business level, I need to create a procedure for every possible restriction so that I can look up before updating or inserting. This is just tedious ... and I duplicate business rules because they exist both in the database and in the business layer, so if something changes, I not only need to change the database, but I need to change the procedure and application code.
So, is there a good way or a good way to enforce these database restrictions in the application code, or should I look for a way to catch the exceptions thrown by the database and present them in a friendly way?
source
share