Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SP Builder Utility
Message
From
29/12/2000 16:13:20
George Simon
GS Data Technologies, LLC
Cincinnati, Ohio, United States
 
 
To
29/12/2000 15:54:38
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00457879
Message ID:
00457940
Views:
20
>Actually, I handle errors in my Data Access class, so there is no need for me to do it directly in the SP. I am open to the suggestion though, for those who wish to do it differently- do you have examples of how you handle errors in your SPs?

Eric,

Here's an example of a DELETE SP that checks for a foreign key constraint violation and then any other errors:

CREATE PROCEDURE usp_community_delete
@nCommunID int,
@nResultCode int=0 OUTPUT
AS

DECLARE @nError int

-- Delete the row.
DELETE FROM community WHERE communid = @nCommunID
SET @nError = @@ERROR

-- Determine if a foreign key constraint has been violated.
IF @nError = 547
BEGIN
RAISERROR('This community is already in use and cannot be deleted.',11,1)
GOTO err_handler
END

-- Check for any other non-fatal errors.
IF @nError <> 0
BEGIN
RAISERROR('Unable to delete this community.',11,1)
GOTO err_handler
END

-- The DELETE was successful.
RETURN @nResultCode

-- Error Handler
err_handler:
SET @nResultCode = -1003
RETURN @nResultCode


I typically check the @@ERROR function after every SQL statement. If an error occurs, the message can can be retrieved using AERROR() in my data service object (have to do some parsing.)
George Simon, MCP
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform