.netsql-servert-sqlado.netsql-server-administration

Can I run DBCC CHECKDB from .NET?


I am writing a scheduled job to mimic a SQL Server maintenance plan for SQL Express. (I have to do this because SQL Agent and related tools don't exist for SQL Express)

One of the steps is to do a database integrity check. The TSQL for this is:

DBCC CHECKDB(N'Northwind')  WITH NO_INFOMSGS

How do I know if an error occurred during execution of this command, will it throw an Exception when using ADO.NET or would I have to parse the text output of the command (if so what do I look for in the output)

This is difficult to test because I don't have a corrupt database on hand.


Solution

  • Yes I believe you would need to process the text output returned from DBCC CHECKDB.

    To assist with your testing, the following reference details how to deliberately corrupt a SQL Server Database.

    http://sqlblogcasts.com/blogs/tonyrogerson/archive/2007/03/10/how-to-create-a-corrupt-database-using-bulk-insert-update-and-bcp-sql-server-as-a-hex-editor.aspx