Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling Database Errors In App
Message
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01435056
Message ID:
01435066
Vues:
42
>I created this stored proc:
>
>
>
>CREATE PROCEDURE wit_DeleteCompany
>	@CompanyKey	int
>AS
>
>BEGIN
>
>	-- If the company key does not exist in the clients table...
>	IF NOT EXISTS(SELECT CompanyKey
>					FROM wit_Clients
>					WHERE CompanyKey = @CompanyKey)
>
>		BEGIN
>
>			-- Delete the address records
>			DELETE FROM wit_Addresses
>				WHERE AddressKey IN
>					(SELECT AddressKey
>						FROM wit_CompanyAddresses
>						WHERE CompanyKey = @CompanyKey)
>
>			-- Delete the CompanyAddress link table records
>			DELETE FROM wit_CompanyAddresses
>				WHERE CompanyKey = @CompanyKey
>
>			-- Delete the company record
>			DELETE 
>				FROM wit_CompanyInfo
>				WHERE CompanyKey = @CompanyKey
>
>		END
>
>	ELSE
>
>		RAISERROR('Company key is in use and cannot be deleted', 18, 0)
>
>	END
>
>
>It ensures that a company is not in use before deleting it.
>
>1) Is there anything wrong with doing it this way

I would put 3 delete statements inside explicit transaction

>2) How do you differentiate in you C# app between this kind of issue and a real error.

You can catch SQLException separately to other exceptions.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform