SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Determining Result of a job started with sp_start_job


Determining Result of a job started with sp_start_job

Author
Message
#1CoolGuy
#1CoolGuy
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 118
I have an SSIS package that I have added as a job in SQL Server 2005. The SSIS package runs a query and creates a csv with the results. The plan is to have the end user be able to execute the SSIS package through an ASP.Net 2.0 application and create the csv they need whenever they need to.
I have a stored proc that starts the job using sp_start_job.
Everything works just fine, however, If something goes wrong I need to be able to tell the end user. What is the best way to determine the result of a job you started through the sp_start_job?
vidhya sagar
vidhya sagar
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1914 Visits: 620
Inside the SSIS package you can make use of "On failure" flow to show the users the error

Regards..Vidhya Sagar
SQL-Articles
#1CoolGuy
#1CoolGuy
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 118
Thanks Vidhya but, If I am starting the job with sp_start_job I don't see how he "on error" in the SSIS package will help me.
I figure I can query the sysjobhistory table to determine the last execution status for that job, however, this seems like a problem that lots of you SQL Experts would have run into in the past and I was wondering if there was a cleaner/ better way to do this that I am not thinking of.

Thanks
Yuri Ivann Cano
Yuri Ivann Cano
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 20
private void exec_job()
{
try
{
SqlConnection jobConnection;
SqlCommand jobCommand;
SqlParameter jobReturnValue;
SqlParameter jobParameter;
int jobResult;

jobConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SQL_Job"].ToString());
jobCommand = new SqlCommand("sp_start_job", jobConnection);
jobCommand.CommandType = CommandType.StoredProcedure;

jobReturnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
jobReturnValue.Direction = ParameterDirection.ReturnValue;
jobCommand.Parameters.Add(jobReturnValue);

jobParameter = new SqlParameter("@job_name", SqlDbType.VarChar);
jobParameter.Direction = ParameterDirection.Input;
jobCommand.Parameters.Add(jobParameter);
jobParameter.Value = "My Job";

jobConnection.Open();
jobCommand.ExecuteNonQuery();
jobResult = (Int32)jobCommand.Parameters["@RETURN_VALUE"].Value;
jobConnection.Close();

switch (jobResult)
{
case 0:
lblError.Text = "started successfully";
break;
default:
lblError.Text = "failed to start";
break;
}
}
catch (SqlException ex)
{
ClientScript.RegisterClientScriptBlock(typeof(Page), "Error", "alert('" + ex.Message + "')", true);
lblError.Text = ex.Message.ToString();
return;
}
}

If you need the result of the package try with sp_help_job @job_name = 'My Job'
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94767 Visits: 38957
#1CoolGuy (10/26/2007)
Thanks Vidhya but, If I am starting the job with sp_start_job I don't see how he "on error" in the SSIS package will help me.
I figure I can query the sysjobhistory table to determine the last execution status for that job, however, this seems like a problem that lots of you SQL Experts would have run into in the past and I was wondering if there was a cleaner/ better way to do this that I am not thinking of.

Thanks


The SSIS package is running as a step in a SQL Server Agent Job, correct? You set it up so that if the package fails, the job step fails. You then have the as part of the failed job step that it runs another job step that emails all the appropriate parties that the process failed.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search