Solved

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

Posted on 2014-03-20
1
259 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 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 18
Pass through dll 2 33
Not needed 13 53
Copy/Clone an object. 9 10
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now