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.
Maybe this can help you: http://mspowershell.blogspot.com/2008/01/dbcc-check-through-adonetps.html.
EDIT: The link will get you to a blog post that contains the following script: