SQL Server - Backup Error Message
Asked By dbapra
13-Feb-08 05:30 PM

Hi,
Im trying to capture the error message that is thrown while backup.
BACKUP DATABASE TestPradDB TO DISK =
'D:\SQL\Backup\TestPradDB_20080213_Full.bak'
I get the below msg when I try to back up my DB.
Msg 3202, Level 16, State 2, Line 1
Write on "D:\SQL\Backup\TestPradDB_20080213_Full.bak" failed: 112(There is
not enough space on the disk.)
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
I need to capture this msg and store it in a log table.
To do this I tried the below code...
SET @ErrorID = @@ERROR
SELECT @FailureReason = CONVERT(VARCHAR,Text)
FROM sys.messages m
INNER JOIN sys.syslanguages l
ON l.MsgLangID = m.Language_ID
AND l.Name = 'us_english'
WHERE m.Message_ID = @ErrorID
this query returns : %hs is terminating abnormally.
And also I see 2 error msgids in the msg on management studio
Msg 3202, and Msg 3013
However @@Error returns only the latest msgid ie 3013.
Is there a way to capture the first msgid ?
I believe there is a way to do this as I see the same msg being logged in
sql server log.
I assume I may have to build the exact string adding the exact path and the
text in sys.messages. But to do that I would need to capture both the MsgIDs.
What does the ID 112 in "Write on
space on the disk.)" mean? Is it OS level msgid?
Thanks,
Prad
SQL Server 2005
(1)
SQL Server 2000
(1)
SQL Server
(1)
FireUserErrorsAsInfoEventMesseages
(1)
Stored procedure
(1)
Translation
(1)
INNER JOIN
(1)
Backup
(1)
Erland Sommarskog replied...
dbaprad (dbaprad@) writes:
Have you tried to run the BACKUP statement in TRY CATCH:
BEGIN TRY
BACKUP ...
END TRY
BEGIN CATCH
SELECT @failurereason = error_message()
END CATCH
You will still only get one of the errors. Which I don't know off hand.
If you need to get both, you will need to run the script from a client
program and use an API that is able to get both messages for you. If
you use SqlClient it should work, if you use the connection option
.FireUserErrorsAsInfoEventMesseages. (Please check the docs for the
exact name.)
Yes, that is an error from an operating-system call. You see this with
NET HELPMSG 112
(which is good when the text in parens only says "Error not found").
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
dbapra replied...
Thanks for the reply...
Yes I tried TRY CATCH first but then it somewhat similar, I dont get a
conclusive msg as I get in management studio which made me think of
sys.messages and make use of @@Error to get the text...
Runnig the program from client app : Im not into any .Net kind of stuff and
also Im planning to create a scheduled job to do this...
Any TSQL command or system proc to get the text from the OS ErrID 112?
Thanks again...
Prad
Erland Sommarskog replied...
dbaprad (dbaprad@) writes:
You can run a command-line job from a scheduled job. You can also run
an Active-X task, but if you do VBscript, the error handling in ADO is
poor.
As I said in my previous post, you can use NET HELPMSG from the command
line. In the Platfrom SDK you can do the translation with FormatMessage.
I don't know if there is any .Net interface you can call from a CLR
stored procedure.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

MSDE on Windows 2003 R2 box, new DL385G6 - Install Fails during SQL Services SQL Server I have been finding that I am having trouble with the Crystal Reports Server XI installation failing when it is dealing with SQL. So, as a thought and in case there was something wrong with my SQL portion of the isntall. I thought ok, I will try installing the actual MSDE application direct from Microsoft. So, I downloaded the MSDE for SQL 2000 (which is msde2000a.exe), set my switches and off to the races. It quit when
SQL Express: Failed Reinstall SQL Server Dear Setup Experts: I am trying to reinstall SQL Express after playing with it some. I uninstalled it, and now, it refuses to reinstall in the face. Any ideas what this log file means and how I can get SQL Express installed? I really do not want to have to reinstall my whole system. * ** ** Start of Log File Overall summary: Final result: SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup. Exit code (Decimal): -2068643839 Exit facility code: 1203
SQLServer Error: 802, 701, 733 SQL Server SQL Server 2008 on Win2008 R2 x64 Server, 8 GB RAM - running virtualized on VMWare ES-Server Every sunday some maintainance jobs are scheduled to run. Rebuilding indices and statistics fail with There is insufficient memory available in the buffer pool. [SQLSTATE 42000] (SaveAllSchedules) After this the server is no longer reachable: [298] SQLServer Error: 773, SQL Server Network Interfaces: The requested security package does not exist [SQLSTATE 08001] . . . [298] SQLServer Error
Moving database decrease performance SQL Server I have moved database from one SQL2000 on win server to another standalone computer. Both SQL serverers have the same settings, same service pack, enterprise editions. On both SQL servers are tempDB, log file and mdf file on separate disks. The new SQL server is on better computer, has more RAM, beter disks, stronger proc, but all queries are there some guide for this scenario somewhere on the net? Any suggestions? Thank you, Simon SQL Server Programming Discussions SQL Server 2008 (1) SQL Server 2000 (1) SQL Server Books (1
SQL Express Installation Failed on New Windows XP Home SQL Server Hello: I installed SQL Express on my system. I uninstalled and reinstalled it a few times. Eventually, this hosed my system to some extent, and SQL Express would not install. I just had Windows XP Home reinstalled. I have reinstalled the software that I use. Yesterday, I tried to install SQL Express for the first time on this new installation. It failed with Wait on the backed up the entire partition, so I restored it. I am about to try installing SQL Express again today. What should I be considering first? (I am rather badly bitten / gunshy in with NT AUTHORITY \ LOCAL SERVICES. I simply used that for the other three. For SQL Express administrators, I made my account the administrator. My account is system administrator. I have