Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:38:59+00:00 2026-06-05T00:38:59+00:00

I am trying to verify the backup I have just done in c# using

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:39:02+00:00Added an answer on June 5, 2026 at 12:39 am

    Informational messages (with severity less than 10) and PRINT output are returned to the client, and raised as InfoMessage events by the SqlConnection instance. Each event contains a collection of SqlError objects (this is the same class used in SqlException.Errors).

    Here’s a complete example that shows connection state changes, info messages and exceptions. Note that I use ExecuteReader instead of ExecuteNonQuery, but the info and exception results are the same.

    namespace Test
    {
        using System;
        using System.Data;
        using System.Data.SqlClient;
    
        public class Program
        {
            public static int Main(string[] args)
            {
                if (args.Length != 2)
                {
                    Usage();
                    return 1;
                }
    
                var conn = args[0];
                var sqlText = args[1];
                ShowSqlErrorsAndInfo(conn, sqlText);
    
                return 0;
            }
    
            private static void Usage()
            {
                Console.WriteLine("Usage: sqlServerConnectionString sqlCommand");
                Console.WriteLine("");
                Console.WriteLine("   example:  \"Data Source=.;Integrated Security=true\" \"DBCC CHECKDB\"");
            }
    
            public static void ShowSqlErrorsAndInfo(string connectionString, string query)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.StateChange += OnStateChange;
                    connection.InfoMessage += OnInfoMessage;
    
                    SqlCommand command = new SqlCommand(query, connection);
                    try
                    {
                        command.Connection.Open();
                        Console.WriteLine("Command execution starting.");
                        SqlDataReader dr = command.ExecuteReader();
                        if (dr.HasRows)
                        {
                            Console.WriteLine("Rows returned.");
                            while (dr.Read())
                            {
                                for (int idx = 0; idx < dr.FieldCount; idx++)
                                {
                                    Console.Write("{0} ", dr[idx].ToString());
                                }
    
                                Console.WriteLine();
                            }
                        }
    
                        Console.WriteLine("Command execution complete.");
                    }
                    catch (SqlException ex)
                    {
                        DisplaySqlErrors(ex);
                    }
                    finally
                    {
                        command.Connection.Close();
                    }
                }
            }
    
            private static void DisplaySqlErrors(SqlException exception)
            {
                foreach (SqlError err in exception.Errors)
                {
                    Console.WriteLine("ERROR: {0}", err.Message);
                }
            }
    
            private static void OnInfoMessage(object sender, SqlInfoMessageEventArgs e)
            {
                foreach (SqlError info in e.Errors)
                {
                    Console.WriteLine("INFO: {0}", info.Message);
                }
            }
    
            private static void OnStateChange(object sender, StateChangeEventArgs e)
            {
                Console.WriteLine("Connection state changed: {0} => {1}", e.OriginalState, e.CurrentState);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to verify whether an object is null or not, using this
I am trying to verify an OAuth signature generated in code against a known
I'm trying to verify a sandbox transactionReceipt at https://sandbox.itunes.apple.com/verifyReceipt using php and cURL. The
I am trying to verify that a C# string is compliant with XML Schema
I have a simple object I'm trying to serialize using DataContractSerializer. In my unit
I am trying to verify that a string is unique within a MySQL column.
I'm trying to verify the existence of username in DB. I have one field
I'm trying to verify a signed message using a x509 certificate holding a dsa
I'm trying to verify that a directory exists using Fortan90. On various sites I
I am trying to verify if my SQL has been executed correctly, and if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.