Solved

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

Posted on 2014-03-20
1
274 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

733 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