Using C# to create a scheduled job

D

Dave

I need to create an executible that will run on a nightly basis.

The executible is a simple command line statement like:

OSQL -Usa -PmyPasword -n -Q "BACKUP DATABASE msdb TO DISK =
'c:\msdb.dat_bak'"


Is it possible to use C# to create an executible that will run this command
line statement on a scheduled basis?

If so, can anyone give me some general ideas on how to go about this?
 
P

Pieter Jansen van Vuuren

Hello Dave,

Why do you want to do this from C#?
Why don't rather just add a scheduled task?
Or in SQL create a scheduled job?

If you really want to execute this from C# use Process:

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "OSQL.exe";
myProcess.StartInfo.WorkingDirectory = "C:\";
myProcess.StartInfo.Arguments = "-Usa -PmyPasword -n -Q \"BACKUP DATABASE msdb TO DISK = > 'c:\msdb.dat_bak'\"";
myProcess.Start();

out of memory, so it might be buggy, but give it a try.

Cheers

Pieter
 
K

Kevin Yu [MSFT]

Hi Dave,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to start a job in schedule
tasks using C#. If there is any misunderstanding, please feel free to let
me know.

To achieve this, you can either use Process.Start or WMI. The following
thread is a talking on this issue. HTH.

http://groups.google.com/groups?hl=en&lr=&c2coff=1&threadm=Ow6sPfvzBHA.1712%
40tkmsftngp04&rnum=2&prev=/groups%3Fq%3Dschedule%2Btask%2BC%2523%2Badd%26hl%
3Den%26lr%3D%26c2coff%3D1%26selm%3DOw6sPfvzBHA.1712%2540tkmsftngp04%26rnum%3
D2

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top