c# - Should programmatic logic reinforce database logic? -


It seems that there is a strange question, I believe some of you, but I teach myself, I have never done otherwise best practice on me.

In short, suppose I have a database table (Table 1) that is connected to another database table (Table 2). There should be a relationship between them in relation to the record being removed in Table 1, no action should be taken in Table 2 - the record recorded in the table has been referenced, strengthening recordable integrity from the table 1 and record 1 stop

So if I programmatically removed the record in Table 1, which was recorded in Table 2 (for example using ADO .NET), I get an error.

The question is whether should I strengthen a logic by examining the linked records before requesting a record deletion. As far as I see it, it doubles on the check (the questions) and provides additional protection of anyone by changing the relationship in the database, but it also ensures that the argument is still being followed - every inquiry For a small price of resources, but what is the correct way ???

Checking before trying to delete can be a good idea, but IMO is a bit unnecessary (when As long as you do not have only 1 user), because it will not guarantee that it is safe to remove, the status of the database can easily be changed by another user, and can issue orders to be removed during the investigation.

I want to delete the database and then capture and handle specific exceptions if they throw in the code I think that you will get a SqlException in this case and then you will get the error code You have to check which you want to handle.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -