Trapping errors from Restore

  • Does anybody know of a way to trap the first error raised from a failed restore from log?

    If you run a restore command like:-

    RESTORE LOG YOURDATABASENAME FROM

    DISK = 'd:\PATH\FILENAME.trn'

    WITH FILE = 1, STANDBY = 'd:\PATH\FILENAME.ldf', NOUNLOAD, STATS = 1

    Using a trn file which has already been applied you receive error message:-

    Msg 4326, Level 16, State 1, Line 1

    The log in this backup set terminates at LSN 6562000002492400001, which is too early to apply to the database. A more recent log backup that includes LSN 6565000000005600001 can be restored.

    Msg 3013, Level 16, State 1, Line 1

    RESTORE LOG is terminating abnormally.

    Now if you want to handle the occurance of this (trap error 4326) using a try/catch and use ERROR_NUMBER() you get 3013 which is the blanket error number for restor failures.

    Is there a way to trap 4326?

  • My guess is that because there are two errors returned, you only get the last one. I don't see a good way to do this by digging through documentation.

    It's possible that you might get two messages if you were to run this through SMO instead. I know that's not always easy.

    I'll ping someone and see if they have ideas.

  • Thanks Steve

  • Nope - you can only trap the last error returned. Same with corruption errors reported by CHCEKDB.

    Paul Randal
    CEO, SQLskills.com: Check out SQLskills online training!
    Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
    SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
    Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply