RAISERROR used to define custom error message . this error message can be printed from stored procedure when validation failed
RAISEERROR ('invalid ProductID' 5001, 2)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I read about using the RAISERROR hack when using a SQL Server Stored Procedure that goes across a Linked Server.
Just wondering what the Syntax is for RAISERROR within a SQL Server Stored Procedured.
Thanks for your review and am hopeful for a reply.
Thanks!
RAISERROR used to define custom error message . this error message can be printed from stored procedure when validation failed
RAISEERROR ('invalid ProductID' 5001, 2)
Hi,@Bobby P
RAISERROR is used to throw an exception or error.
For example,you can add ERROR CHECKS in stored procedure,like this:
IF (@type_id IS NULL)
BEGIN
RAISERROR ('Parameter ''role_type_id'' can not be null.' , 16, 1) WITH NOWAIT
RETURN 1
END
Please refer to this document for more details.
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
I am specifically referring to this link...
https://dba.stackexchange.com/questions/236584/linked-server-returned-message-query-timeout-expired
That's an interesting approach, that I have not thought of. And a quick test indicates that it works (on SQL 2019, which the poster had not tested.)
But what is really your question? There is an example with RAISERROR right in the StackOverflow post, so why ask here rather than copy and paste?
OK, I understand that your real problem is that you are experiencing a remote query timeout, and I seem to recall that you had a thread about that. I was able to find the thread, and I see that I suggested you to collect query plans, but you never came back with any information.
From that thread, I cannot really determine if this RAISERROR hack is applicable here.
That hack is only applicable under fairly specific circumstances. First of all, you must be calling a stored procedure on the remote server. If you are running a query with four-part notation or OPENQUERY, there is no place where you can inject this RAISERROR.
Next, you must have possibility to edit this procedure. That is, if this is an SP which is part of Dynamics/CRM, it is unlikely that you can change it.
And finally, there must be some place where you can inject the RAISERROR. If the procedure runs a loop or several long-running statements, you can splice it in somewhere. But if the procedure get stuck on the same query for ten minutes, you are out of luck.
By the way, this was your previous thread: https://learn.microsoft.com/en-us/answers/questions/698108/sql-server-job-error-query-timeout-expiredbut-work.html.