Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Referential Integrity
Message
De
15/04/2009 17:09:08
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
15/04/2009 16:52:22
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01394872
Message ID:
01395055
Vues:
58
Hi Sam,

First I agree with your other post that a constraint needs to be in the database for a multitude of reasons in protecting your data. But since you are a defensive programmer it would be better not to leave your program to catching a database constraint as your application method.

When you call a save either directly to the business object or via a form save method you would get a mmSaveDataResult object. That object may be an exception due to the constraint. In my perspective while catching a exception is effective I don't think it should be used as a standard method of testing your save. I personally would implement a test of the data in order to make every effort to reduce the amount of times it would need to be caught via an exception.

The mmSaveDataResult will return either RulesBroken, RulesPassed, RuleWarnings, SaveCanceled, or an Exception. The exception is what you get when there is a constraint error. It is already caught for you, but is a Try Catch none the same.

I hope that helps. Based on your reply to Randy, I think you are on the right track. IMHO anyway.
Tim

>Hi Tim,
>
>Thanks for your reply. Are you saying that in order to display a meaningful exception message to the user in a graceful way that I will need to add Try Catch code somewhere? Where?
>
>Sam
>
>>I would agree with Randy here in that only catching and reporting database errors is a bit of an ineffiecient way to do this. When you wrap your mm Save in a Try Catch you will catch an error which will give you a string result of your database issue. It would be better and more efficient to call the child business object to retrieve all child records for that parent and see if there are any rows returned. This might even be faster than dealing with a caught exception.
>>
>>I would still leave my database constraint in place however, so I would think you need both.
>>Just my thoughts also.
>>Tim
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform