tags:

views:

192

answers:

1

I am trying to execute DBCC CHECK DB('MyDB) using ADO.Net, but how can I get the text returned by the command?

I have tried the following:

SqlCommand sqlCom = new SqlCommand("DBCC CHECKDB ('MyDB')", sqlCon);
SqlParameter output = new SqlParameter();
output.Direction = System.Data.ParameterDirection.ReturnValue;
sqlCom.Parameters.Add(output);
int result = sqlCom.ExecuteNonQuery();
Console.WriteLine(output.Value);

But the output parameter value is empty.

A: 

Maybe this can help you: http://mspowershell.blogspot.com/2008/01/dbcc-check-through-adonetps.html

Konamiman
Thank you, the "WITH TABLERESULTS" made all the difference.
jaffa