August 11, 2017 at 7:37 am
Hi
I'm creating a procedure to validate a database backup file and to record the error messages if it fails. But in some situations i have 2 messages returned from SQL Server but i can only handle the last one like this example:
Mensagem 3241, Nível 16, Estado 0, Line 88
The media family on device '\\xptodir\xptofile.bak' is incorrectly formed. SQL Server cannot process this media family.
Mensagem 3013, Nível 16, Estado 1, Line 88
VERIFY DATABASE is terminating abnormally.
SQL Server returned 2 erros: 3241 and 3013 but the ERROR_NUMBER and ERROR_MESSAGE functions handle only the last one. Is there anyway to handle all the messages?
August 16, 2017 at 10:52 am
Jose Marcelo Dias de Oliveira - Friday, August 11, 2017 7:37 AMHiI'm creating a procedure to validate a database backup file and to record the error messages if it fails. But in some situations i have 2 messages returned from SQL Server but i can only handle the last one like this example:
Mensagem 3241, NÃvel 16, Estado 0, Line 88
The media family on device '\\xptodir\xptofile.bak' is incorrectly formed. SQL Server cannot process this media family.
Mensagem 3013, NÃvel 16, Estado 1, Line 88
VERIFY DATABASE is terminating abnormally.SQL Server returned 2 erros: 3241 and 3013 but the ERROR_NUMBER and ERROR_MESSAGE functions handle only the last one. Is there anyway to handle all the messages?
Not sure how you are doing this or what you are doing to handle the messages but you can capture multiple errors messages using THROW which was introduced in SQL Server 2012. Basic example would be something like:
BEGIN TRY
BACKUP DATABASE Test
TO DISK='Q:\SomeFolderThatDoesNotExist\test.bak'
END TRY
BEGIN CATCH
THROW;
END CATCH
Sue
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply