• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Why isn't this query working?

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
IzzyTwinkly
Asked:
IzzyTwinkly
  • 4
  • 3
1 Solution
 
Anurag ThakurTechnical ManagerCommented:
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
 
IzzyTwinklyAuthor Commented:
could you please tell me how? Also, it's working well on my desktop.  It's just not working on the server.
0
 
Anurag ThakurTechnical ManagerCommented:
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Anurag ThakurTechnical ManagerCommented:
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
 
IzzyTwinklyAuthor Commented:
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
 
Anurag ThakurTechnical ManagerCommented:
try the command timeout option and see if it works
0
 
IzzyTwinklyAuthor Commented:
You are the Man!  Thanks~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now