Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
How to find the sql exception in stored procedure.


What I have tried:

How to find the sql exception in stored procedure. try catch is proper approach or any other things are there to find out exceptions
Posted
Updated 18-Jun-16 9:27am
Comments
Maciej Los 18-Jun-16 15:14pm    
What RDBMS?
Sergey Alexandrovich Kryukov 18-Jun-16 15:21pm    
What does it mean, "find exception"? This is not how exception handling works. Anyway, the question is unclear.
—SA

1 solution

Please see my comment to the question. I cannot understand what you mean and not sure that you understand what you want to achieve, sorry.

Anyway, exception handling is the feature of Transact-SQL, which is the extension to SQL, so you may want to start here:
TRY...CATCH (Transact-SQL),
Transact-SQL.

However, mostly likely, you need to understand how exception handling works, which is not a trivial topic, despite the fact that nearly everyone uses exception handling. I tried to explain just the general idea in my past answers:
Does Exception in C# Constructor Cause Caller Assignment to Fail?,
where was stored .net exceptions in operating system.

The topic is quite fundamental and serious, takes real education; my answered can be considered as just the hint, at best.

—SA
 
Share this answer
 
Comments
DGKumar 21-Jun-16 4:47am    
I have faced the question in one interview that.
how can you know the stored procedure get any error.
What is your approach to find out where exactly happen mistake in storedprocedure?
Sergey Alexandrovich Kryukov 21-Jun-16 9:41am    
Look at exception information...

Look at this page again: https://msdn.microsoft.com/en-us/library/ms175976.aspx.
Pay attention for:

Retrieving Error Information
...
ERROR_NUMBER() returns the number of the error.
ERROR_SEVERITY() returns the severity.
ERROR_STATE() returns the error state number.
ERROR_PROCEDURE() returns the name of the stored procedure or trigger where the error occurred.
ERROR_LINE() returns the line number inside the routine that caused the error.
ERROR_MESSAGE() returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times.
...

Doesn't it means that I already answered your question, because I referenced this page in my answer in first place?
Will you accept the answer formally now?

—SA

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