1

I have created a windows application that triggers a SQL job to start on the SQL Server. This is how I have written the code to trigger the job.

SqlCommand ExecJob = new SqlCommand();

ExecJob.Connection = sqlConn;
ExecJob.CommandType = CommandType.StoredProcedure;
ExecJob.CommandText = "msdb.dbo.sp_start_job";
ExecJob.Parameters.AddWithValue("@job_name", "DataImport");

sqlConn.Open();
ExecJob.ExecuteNonQuery();

It runs fine and completes in about 40 seconds. I do not want to enable some certain functions in my program until this job is completed successfully. Does anyone know how I can do this?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Leyth G
  • 1,103
  • 2
  • 15
  • 38
  • 3
    Don't understand your question. Why don't you enable your functions right after ExecuteNonQuery is finished? – Rick S Mar 24 '14 at 20:44
  • possible duplicate of [How can I determine the status of a job?](http://stackoverflow.com/questions/200195/how-can-i-determine-the-status-of-a-job) – John Saunders Mar 24 '14 at 21:00
  • ExecuteNonQuery is just a query to start the job. The job could take 40 seconds, but SqlCommand isn't going to sit and wait for it. – Leyth G Mar 25 '14 at 13:12

2 Answers2

1

Here you can find a post that shows how to get the status of sql jobs.

How can I determine the status of a job?

Then, you just need to define a timer that pools the database and request the job status.

Community
  • 1
  • 1
ogomrub
  • 146
  • 2
  • 7
0

I think I sort of understand your question... The best way to do this would be to set the output of your stored proc to a specific value, then pass that value into your program and check the value to see weather your functions should be enabled or disabled based on whether or not the proc has ran successfully.

Alec.
  • 5,371
  • 5
  • 34
  • 69