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
Titre:
Handling Database Errors In App
Divers
Thread ID:
01435056
Message ID:
01435056
Vues:
83
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
2) How do you differentiate in you C# app between this kind of issue and a real error.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform