IzzyTwinkly
asked on
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();
}
}
}
}
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();
}
}
}
}
ASKER
could you please tell me how? Also, it's working well on my desktop. It's just not working on the server.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry forgot to ask one thing - how much time its takes if you run the queru from the query window on the server machine
ASKER
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.
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.
try the command timeout option and see if it works
ASKER
You are the Man! Thanks~~~~~~~~~~~~~~~~!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !
set the command timeout to 0 (infinite) and try again