pilotboba wrote:
Yes that is possible. How likely is that in your environment?
I guess you could parse out the error message looking for the Index name or FK name and send the approriate message based on that.
But, I still do the check up front also. If the value already existis when the user enters that value better they know right away rather than waiting for after they press SAVE.
I'll have to think about this. It sounds like a good idea except that it may need to re-run the duplicate key check on every validate, as it could be a long time before the user hits the SAVE button, and other users could easily have slipped in a new record behind the scenes.
pilotboba wrote:
I still recommend following the same pattern. This is once again a business rule. Enforcing these interentity relations in the db is just a saftey net. Not something to rely on.
Unfortunately, our group consists of some db guys who sometimes like to go behind the scenes and alter data directly in the table, causing us to need business rules in the database itself
Putting the logic in the code would be duplicating the business rules, which we try to avoid at all costs (as changing the rules cannot just be done in one place which can lead to maintenance issues).
pilotboba wrote:
Once again, you can parse the FK name out of the error message in order to send the correct message to the UI tier. You should even use the FK name or Indexname as a key to a resource item.
The question I would ask is, if you check up front and then do your update/insert/delete there is a very small chance that in the few milliseconds between the check and the data change that the prechecked state would change.
If after doing this you are getting UC or FK violations exceptions at a high rate you can deal with it then. But, those db constraints (saftey net) will keep your data intact.
BTW: This is one of the few advantages you get by using stored procs.
BOb
I agree that there is a very small chance that something could slip in in that fraction of a second, but its possibility would just be one more thing to remember when trying to debug our app in case of failure. I'm not saying that this should mean we shouldn't do it, just that I'd really like to figure out a better way