I am trying to verify the backup I have just done in c# using command against sql server Express
string _commandText = string.Format("RESTORE VERIFYONLY FROM DISK = '{0}'", backupLocation);
SqlDataReader _sqlDataReader = SqlHelper.ExecuteReader("BookssortedSQLDbConnection", CommandType.Text, _commandText);
If I execute the command in SSMS it returns ‘The backup set on file 1 is valid.’ but how can I get this message back into my code?
A reader wont work as there are no rows being returned.
NOTE: I have tried the SMO.Restore object to try and verify it but it doesn’t work and that is why I am doing it this way.
_restore.SqlVerify(srv, out _errorMessage); //returns false even though bakcup is fine
BTW – Open to suggestions as I don’t think this is the ideal way to achieve what I am trying to do
Informational messages (with severity less than 10) and PRINT output are returned to the client, and raised as
InfoMessageevents by theSqlConnectioninstance. Each event contains a collection ofSqlErrorobjects (this is the same class used inSqlException.Errors).Here’s a complete example that shows connection state changes, info messages and exceptions. Note that I use
ExecuteReaderinstead ofExecuteNonQuery, but the info and exception results are the same.