I have a small script generator which will try to find which folder a backup file needs to be restored to and eventually print the restore script in the messages section in SSMS. During location of the backup folder I also check the DefaultData path using xp_instance_regread extended procedure, if the path found things are find but if the path is not found I get the message "RegOpenKeyEx() returned error 2, 'The system cannot find the file specified." printed by the extended procedure which is also printed to the user and after that the code skips to the next search for restore folder and eventually prints the restore script to the user. I want to avoid the user (person executing the stored proc that generates the restore script) from seeing this message. I tried try catch around xp_instance_read but that does not change the behavior.
Is there a way to avoid the message generated by xp_instance_regread procedure?
Thank you
DECLARE @DataPath VARCHAR(128) , @Return INT EXEC @Return = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE' , N'Software\Microsoft\MSSQLServer\MSSQLServer' , N'DefaultData' , @DataPath OUTPUT; SELECT @Return AS [@Return] , @DataPath AS [@DataPath]
If the value not found below error will be printed.
RegOpenKeyEx() returned error 2, 'The system cannot find the file specified.'Msg 22001, Level 1, State 1
Gokhan Varol