Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Procedure exception handling

Author  Topic 

Jan Hodac
Starting Member

1 Post

Posted - 2011-09-19 : 07:01:01
Hi, i have problem with exception handling in procedure. I want to backup DB through BACKUP DATABASE. In case of exception I dont know how to get all exceptions. For example when use

BACKUP DATABASE @databasename TO DISK=''

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

but when I use

BEGIN TRY
BACKUP DATABASE @databasename TO DISK=''
END TRY
BEGIN CATCH
SELECT @error= CAST(ERROR_NUMBER() as varchar) + ' ' + ERROR_MESSAGE();
END CATCH;

I get only the second exception

3013 BACKUP DATABASE is terminating abnormally.

Is any way to get both exception please.
   

- Advertisement -