[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-03-20
1
Medium Priority
?
307 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
1 Comment
 
LVL 25

Accepted Solution

by:
apeter earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
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 how to implement Singleton Design Pattern in Java.
Suggested Courses

834 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