?
Solved

Why isn't this query working?

Posted on 2009-04-29
7
Medium Priority
?
195 Views
Last Modified: 2012-05-06
Hi I got this query from SQL mgmt. studio, but when I executed the code, myDB.bak was created, showing myDB.bak with 0KB, then it disappeared.  Why my code is not working?

I am using MS Windows Server 2003

using System;
using System.Data.SqlClient;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string conStr = "server = localhost; database = myDB; user id = sa; password =  ";
                string query = @"BACKUP DATABASE [myDB] TO  DISK = N'C:\myDB.bak' WITH NOFORMAT, INIT,  NAME = N'myDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10";
                SqlConnection conn = new SqlConnection(conStr);
                conn.Open();

                SqlCommand comm = new SqlCommand(query, conn);
                comm.ExecuteNonQuery();


                conn.Close();
            }
            catch (Exception e)
            {
                e.Message.ToString();
            }
        }
    }
}
0
Comment
Question by:IzzyTwinkly
  • 4
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24266826
the backup process might be talking more than 30 seconds - the default for command timeout
set the command timeout to 0 (infinite) and try again
0
 

Author Comment

by:IzzyTwinkly
ID: 24267118
could you please tell me how? Also, it's working well on my desktop.  It's just not working on the server.
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 24267270
0
Industry Leaders: 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!

 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24267275
sorry forgot to ask one thing - how much time its takes if you run the queru from the query window on the server machine
0
 

Author Comment

by:IzzyTwinkly
ID: 24267325
Thanks raqi0017!

definitely less than 30 seconds.  I would say around 5-10sec.  I just don't understand why it's working on my desktop and not working on the server.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24267342
try the command timeout option and see if it works
0
 

Author Comment

by:IzzyTwinkly
ID: 24267425
You are the Man!  Thanks~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

612 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