3

When I run something like

BACKUP LOG [somedb] 
TO DISK = N'i:\log.bak';

It throws 2 errors messages:

Msg 3201, Level 16, State 1, Line 2
Cannot open backup device 'i:\log.bak'. Operating system error 3(The system cannot find    the path specified.).
Msg 3013, Level 16, State 1, Line 2
BACKUP LOG is terminating abnormally.

When I try to handle the error with a TRY CATCH the error returned is always 3013. This is a problem for me because I want to know if the backup failed due to lack of space, or if the drive isn't present, etc.

Using @@ERROR returns the same error number.

Is there any way to handle multiple error messages like these?

1 Answer 1

4

You need to inspect the Errors collection inside the SqlException:

catch(SqlException sqlEx)
{
    foreach(SqlError error in sqlEx.Errors)
    {
       int code = error.Number;
       string msg = error.Message;
    }
 }

You should get all error with all relevant details in the SqlException.Errors

Sign up to request clarification or add additional context in comments.

3 Comments

@MikeDaSpike: no, not to my knowledge - not even with the TRY..CATCH mechanism :-(
@Mike - Not easily. DBCC OUTPUTBUFFER(@@spid). might be able to do it but you'll need to figure out how to parse the output
Damn, I guess it's an excuse to go into C#. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.