When I try below:
backup database not_existing_db to disk = 'E:\Backup\not_existing_db.bak'
SSMS shows two error messages:
Msg 911, Level 16, State 11, Line 22 Database 'not_existing_db' does not exist. Make sure that the name is entered correctly. Msg 3013, Level 16, State 1, Line 22 BACKUP DATABASE is terminating abnormally.
When I try to encapsulate it into TRY...CATCH block like below:
begin try backup database not_existing_db to disk = 'E:\Backup\not_existing_db.bak' end try begin catch select ERROR_MESSAGE() end catch
error_message() only shows second error which is not informative at all
I want to find a way to log both messages, so most informative error message (first) could be send by email to DBA
Please help to find out how to do that