Trapping DBCC Errors

  • Hi

    Is it possible to trap a DBCC error as part of a SP and react accordingly.

    E.G. I have an SP that uses a cursor to loop through my tables rebuilding indexes using DBCC DBREINDEX. If one of these fails due to space constraints, then I would prefer to move onto the next table. Currently, the SP fails.

    something like

    CURSOR

    dbcc dbreindex(...)

    if "no error" or "ERROR = lack of space"

    fetch next

    else

    quit

    I tried @@ERROR, but I don't think that applies to DBCC. I could try to work out if there's space before I attempt rebuild.

    Any help would be appreciated.

    Thanks

    Andy

  • Hi,

    Try this .....

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;115519

    Andy.


    Andy.

  • Hi.

    Not sure that this is what I was after (although there's some useful stuff here). What I was looking for was an equivalent to @@ERROR for dbcc commands

    In TSQL, you could do

    insert into table values .....

    if @@ERROR = 'You ran out of space' then continue

    else quit

    There doesn't seem to be a dbcc equivalent e.g.

    dbcc dbreindex ...

    if @@ERROR = 'You ran out of space' then continue

    else quit

    doesn't trap the error.

    Andy

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

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