February 21, 2008 at 4:56 pm
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.
February 21, 2008 at 6:51 pm
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
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply