Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If there is any exception in the written Stored Procedure then how to handle it? Throwing that from SP and then handling it in ASP.NET code at the front end?
Posted
Updated 3-Feb-10 23:50pm
v3

These links would help you to go ahead:
Exception Handling in SQL Server 2000 and 2005[^]

Exception Handling in SQL Server 2000 and 2005-2[^]

About handling in ASP.NET, you can pass on the desired return value from error handled in SQL or based on the return value you can handle it easily in UI level.
 
Share this answer
 
You can't technically throw an exception from a stored proc. You candle them *in* the stored proc and return some sort of an error message back to the calling front end (through the SqlCommand.Parameters property).

If you don't handle the exceptions in the stored proc itself, the framework will throw database-related exceptions that you can handle in the front end-code.

Where you handle the exception is dependent on what your code is doing. If you want to be able to rollback a transaction, you could do it in either the stored proc or the front-end, but again, that depends on how you're performing transactions.
 
Share this answer
 
Hi
Inside the store procedure use beging catch to catch the exception as shown below which will return you the error number, errormessage, error line....

BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH

hope this will help you. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900