Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

How to get a better error message back?

$
0
0
I run this piece of code:[code="sql"] BACKUP DATABASE template TO DISK = '\\myserver\Backup\SQL2012\template\template_newdb.bak' WITH FORMAT, MEDIANAME = 'LATEST template NEWDB', NAME = 'Full Backup of template NEWDB'[/code]Then I get the expected message:[code="sql"]Msg 911, Level 16, State 11, Line 48Database 'template' does not exist. Make sure that the name is entered correctly.Msg 3013, Level 16, State 1, Line 48BACKUP DATABASE is terminating abnormally.[/code]Now I run this code:[code="sql"] BEGIN TRY BACKUP DATABASE template TO DISK = '\\myserver\Backup\SQL2012\template\template_newdb.bak' WITH FORMAT, MEDIANAME = 'LATEST template NEWDB', NAME = 'Full Backup of template NEWDB' END TRY BEGIN CATCH SET @msg = 'BACKUP template FAILS: ' + ERROR_MESSAGE() END CATCHSELECT @msg[/code]I get as message:[code="sql"]BACKUP DATABASE is terminating abnormally.[/code]What must I do to get something like:[code="sql"]Database 'template' does not exist. Make sure that the name is entered correctly.BACKUP DATABASE is terminating abnormally.[/code]Thanks!

Viewing all articles
Browse latest Browse all 3145

Trending Articles