Getting Started with ASP.NET MVC - Part 6: ASP.NET MVC and Entity Framework
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 113
sqlserver 94
BRH 78
#SQLServer 65
#TSQL 55
SQL Server 32
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2011 7
November 2007 7
November 2011 6
August 2011 6
October 2011 6
July 2011 6
September 2011 6
December 2011 6

Madhivanan's TSQL Blog

Question of the month December 2011 - How will you capture multiple error messages?

Dec 14 2011 1:08AM by Madhivanan   

Assume that there is a database named test in the server and you want to take a backup of that database. Run the following code without specifying the path

backup database test to disk=''

You will get the following error messages

Msg 3044, Level 16, State 2, Line 1
Invalid zero-length device name. Reissue the BACKUP statement with a valid device name.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.

You can however capture the error message programatically using TRY CATCH block as shown below

begin try
	backup database test to disk=''
end try
begin catch
	select  error_message() as [error_message]
end catch

But it captures only the last error message BACKUP DATABASE is terminating abnormally

How will you capture first error message too along with second error message?

Tags: tsql, SQL Server, #TSQL, #SQLServer,


Madhivanan
4 · 39% · 8850
4
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Question of the month December 2011 - How will you capture multiple error messages?" rated 5 out of 5 by 4 readers
Question of the month December 2011 - How will you capture multiple error messages? , 5.0 out of 5 based on 4 ratings
    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising