Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to capture raiseerror warnings from mssql stored procedure

I am using tDBSP to call MS SQL stored procedure.  I can get the Out parameters, resultset parameters and '@RETURN_VALUE from the SP but I could not get the raiseError exception thrown from SP.   I have tried the below options to capture the exception in the job but I could not.

1. globalMap.get("tDBSP_1_ERROR_MESSAGE") . - Returning null

2. tAssertCatcher/tLogCatcher 

 

POC Store procedure

    BEGIN

       DECLARE @ErrMsg NVARCHAR(4000) ,@ErrSeverity INT

       SELECT  @ErrMsg = 'Test Error' , @ErrSeverity = -1

       RAISERROR(@ErrMsg, @ErrSeverity, 1)

    END

 

Please see the attached screen shot from DB Visualizer when I try to execute the SP directly.  Is there any way i can capture the Warning  in Talend.

 

0683p000009M34j.png

 

Labels (1)
  • v7.x

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

The tlogcatcher get the RAISEERROR exception message from SP.  Incase any one looking for the solution.

View solution in original post

7 Replies
Anonymous
Not applicable
Author

Hi,

 

    Could you please try to use it as function where you can capture the error value inside SP itself and send them as a return value with a specific return code (say -3 instead of normal return value of 0)

0683p000009M3Du.png

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

Anonymous
Not applicable
Author

Thanks nikhil.  I am already using isFunction and get the return value.  The issue is how to get the RaiseError message from SP.

Anonymous
Not applicable
Author

Hi,

 

    Could you please try below method where you are passing the data to an output variable and send it to a tFlowtoIterate.

0683p000009M3Fg.png

 

Then you can verify whether the status is not equal to 0 by a Run if condition.

0683p000009M3Fl.png

 

I dont have a MSSQL server handy with me. So I could not personally test it. But I believe this flow in its exact form or with minor modifications should work fine.

 

Could you please try it out and let me know the results?

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

Anonymous
Not applicable
Author

Thanks Nikhil.

 

I already have the same steps to get the return value using 'Is Function'  and verify the SP is returning 0 or something else.  The tFlowIterate doesnt help with the

RAISERROR messages from Stored Procedure.

 

Anonymous
Not applicable
Author

Hi,

 

    Are you using Try catch block in the Stored Procedure so that any error can be caught within Stored Procedure itself and can be converted to appropriate return values?

 

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql?view=sql-server-...

 

Once you are handling the error messages within Stored Proecedure and converting them to proper return values, my understanding is that you will be able to manage them using tFlowtoIterate as shown above.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

 

Anonymous
Not applicable
Author

Yes Nikhil. I am using try ... catch block in the Stored Procedures with user defined error message. (    Are you using Try catch block in the Stored Procedure so that any error can be caught within Stored Procedure itself and can be converted to appropriate return values?)

 

In the Talend I am trying to get the User defined Error Message and store it in the log and another error table.    But not sure how to get the RAISERROR messages in tDBSP.  I have tried the OUT/RECORD SET type but getting error saying invalid column name .    I am already getting the returnvalue (that is not an issue).   Based on the return value i can handle further steps for SP success/failure steps .  tFlowtoIterate doesnt help to get the RAISERROR messages.

 

Here is the raiseerror doc:

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/raiserror-transact-sql?view=sql-server-...

 

Anonymous
Not applicable
Author

The tlogcatcher get the RAISEERROR exception message from SP.  Incase any one looking for the solution.