Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all friends,
I have a sql store precedure called MakeLogging to log errors.
I use try catch in my script and within that catch i have called MakeLogging sp as below.
But is give me error, please help me to solve this.
SQL
DECLARE	@return_value int
		EXEC	@return_value = [dbo].[MakeLogging]
				@LogTypeId = 5,
				@Description = 'Error: at SaveArticle SP',
				@UserId = @UserId,
				@ErrorNumber = ERROR_NUMBER,
				@ErrorServerity = ERROR_SEVERITY,
				@ErrorState = ERROR_STATE,
				@ErrorProcedure = ERROR_PROCEDURE,
				@ErrorLine = ERROR_LINE,
				@ErrorMessage = ERROR_MESSAGE,
				@Status = 1

		RETURN @return_value


What I have tried:

I have tried lot and couldn't do. please help me.
Posted
Updated 10-Dec-16 1:16am
Comments
Suvendu Shekhar Giri 10-Dec-16 5:44am    
What is the error?
Show us what have you written in your store procedure and we'll try to help you out.
Member 11670657 10-Dec-16 5:50am    
Thanks Suvendu,
I think error is @ErrorNumber = ERROR_NUMBER.
When i use @ErrorNumber = NULL,
it works fine. But i want Error number and other details. How can i assign them to variables of MakeLogging sp?
Suvendu Shekhar Giri 10-Dec-16 6:42am    
Well, ERROR_NUMBER is a function.
Example-
SELECT ERROR_NUMBER()
Member 11670657 10-Dec-16 6:53am    
but why can't i use as @ErrorNumber = select ERROR_NUMBER(),

If I understand the situation correctly, you need to catch the error and place information from that error to variables which you then again pass to the procedure (or use the values directly).

For example you now try to pass ERROR_NUMBER to the procedure, but it isn't a variable or a function. Try for example using ERROR_NUMBER() instead. In other words,
SQL
...
@UserId = @UserId,
@ErrorNumber = ERROR_NUMBER(),
...
 
Share this answer
 
Why don't you have the query that threw the error log it instead of making the app do it?
 
Share this answer
 
Comments
Member 11670657 10-Dec-16 7:24am    
I want to insert them in DB

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