Solved

Backup with Async prograning "cmd.EndExecuteNonQuery(result)" is -1 although backup created?

Posted on 2014-03-20
1
279 Views
Last Modified: 2014-08-17
            string connString = string.Format("Data Source=MY_SERVER;Initial Catalog=master;Integrated Security=True");
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connString);
            builder.AsynchronousProcessing = true;
            using (SqlConnection sqlConnection1 = new SqlConnection(builder.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("BACKUP DATABASE [TEST_DB] TO  DISK = N'\\\\servername\\foldername\\backup.bak' WITH NOFORMAT, INIT,  NAME = N'Full_Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 100", sqlConnection1))
                {
                    sqlConnection1.Open();


                    IAsyncResult result = cmd.BeginExecuteNonQuery();



                    result.AsyncWaitHandle.WaitOne();



                    int  rs = cmd.EndExecuteNonQuery(result);
      }
            }

Open in new window


The "EndExecuteNonQuery(result)"  "rs"  is  -1 not 1

why? how can i know it's success?
0
Comment
Question by:center1010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
apeter earned 500 total points
ID: 39950260
EndExecuteNonQuery returns number of rows affected and here the case is it is taking a backup.

As long as you didn't had any error thrown, mean backup is success.  Also you can check whether the .bak file is created and its size is more than zero at the end if you want.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question