dbTalk Databases Forums  

SQL Error handling in SP

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SQL Error handling in SP in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jimbo
 
Posts: n/a

Default SQL Error handling in SP - 06-22-2010 , 09:49 AM






SQL2000 SP4.

I have a SQL Store Procedure that performs a database backup, to a
disk file, for each 'user' database in the SQL instance. The script is
simple; it just uses a 'fetch' loop and performs a 'BACKUP
DATABASE...' for each database.

If I run the script in QA, and one of the database backups fails for
any reason - backup disk full, path not found etc., the script just
loops through to the next database. Which is what I want.

However, if I then run the SP as a scheduled job, the job fails, and
does not continue to the next database backup.

How can I get the SP to ignore the BACKUP DATABASE failure(s) when
it's executed from a scheduled job? I guess these are O/S errors being
passed back to SQL.

Thanks very much. James.

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: SQL Error handling in SP - 06-22-2010 , 01:12 PM






Jimbo (james.goodwill (AT) googlemail (DOT) com) writes:
Quote:
I have a SQL Store Procedure that performs a database backup, to a
disk file, for each 'user' database in the SQL instance. The script is
simple; it just uses a 'fetch' loop and performs a 'BACKUP
DATABASE...' for each database.

If I run the script in QA, and one of the database backups fails for
any reason - backup disk full, path not found etc., the script just
loops through to the next database. Which is what I want.

However, if I then run the SP as a scheduled job, the job fails, and
does not continue to the next database backup.

How can I get the SP to ignore the BACKUP DATABASE failure(s) when
it's executed from a scheduled job? I guess these are O/S errors being
passed back to SQL.
In SQL 2000, you cannot suppress errors. The problem is that Agent aborts
the job on errors.

I think the easiest way out is to run the job as a CmdExec job, and
in this job you invoke OSQL to run the procedure.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.