Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Determining Result of a job started with sp_start_job Expand / Collapse
Author
Message
Posted Thursday, October 25, 2007 2:27 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 26, 2010 9:47 AM
Points: 49, 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?
Post #415115
Posted Friday, October 26, 2007 2:42 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 1:31 PM
Points: 416, Visits: 573
Inside the SSIS package you can make use of "On failure" flow to show the users the error

Regards..Vidhya Sagar
SQL-Articles
Post #415272
Posted Friday, October 26, 2007 9:19 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 26, 2010 9:47 AM
Points: 49, 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
Post #415467
Posted Tuesday, September 18, 2012 5:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, August 8, 2014 11:54 AM
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'

Post #1361061
Posted Tuesday, September 18, 2012 5:44 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 5:05 PM
Points: 20,738, Visits: 32,520
#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.



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)
Post #1361064
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse