Try Catch not working properly | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Try Catch not working properly

SET XACT_ABORT off
BEGIN TRY
exec master..xp_servicecontrol ‘QueryState’,’ABC’
END TRY
BEGIN CATCH
SELECT
–ERROR_NUMBER() AS ErrorNumber,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH; I tried to execute this script, but that catch statement not able to catch the errors. Msg 22003, Level 16, State 1, Line 0
OpenService() returned error 1060, ‘The specified service does not exist as an installed service.’ Thanks
S. Ramesh
Ensure the SQLAgent has been started when executing this program. Satya SKJ
Microsoft SQL Server MVP
Writer, Contributing Editor & Moderator
http://www.SQL-Server-Performance.Com
This posting is provided AS IS with no rights for the sake of knowledge sharing. Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it.
Hi,
Try and catch block has been written correctly. I think you are still getting error, might be because of raiseerror event present in xp_servicecontrol.
I believe in this case sql is not getting the handle back properly… What you are trying to accomplish? MohammedU.
Microsoft SQL Server MVP
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

]]>