Corruption Detection Issue

  • I'm a developer trying to write some corruption detection into my application (Delphi) when it backs up and restores a database, and I want to be able to read the results of a dbcc checkdb and a restore verifyonly command into a result set so I can pull it back into my application. Is there a way to do this? If not, can anyone suggest another way of storing the results and allowing me to retrieve them? Thanks.

  • Yes, you can save the result set in a table by using a kind of "back door" way using a call to OSQL....

    --===== Create a temp table to hold the results of the DBCC command

    IF OBJECT_ID('TempDB..#DBCCResult','U') IS NOT NULL

    DROP TABLE #DBCCResult

    CREATE TABLE #DBCCResult

    (

    RowNum INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,

    Result VARCHAR(256)

    )

    --===== Using XP_CmdShell to "come in the back door", using

    -- OSQL to execute the DBCC command and capture the output

    INSERT INTO #DBCCResult

    (Result)

    EXEC Master.dbo.xp_CmdShell 'OSQL -S"serverinstancenamehere" -dPUBS -Q "DBCC CHECKDB (''pubs'',NOINDEX)" -E'

    --===== Display the output of the DBCC command

    SELECT *

    FROM #DBCCResult

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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