Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 General Discussion
»
Determining Result of a job started with...
Determining Result of a job started with sp_start_job
Rate Topic
Display Mode
Topic Options
Author
Message
#1CoolGuy
#1CoolGuy
Posted Thursday, October 25, 2007 2:27 PM
SSC 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
vidhya sagar
vidhya sagar
Posted Friday, October 26, 2007 2:42 AM
SSC-Addicted
Group: General Forum Members
Last Login: Tuesday, March 19, 2013 2:45 AM
Points: 416,
Visits: 521
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
#1CoolGuy
#1CoolGuy
Posted Friday, October 26, 2007 9:19 AM
SSC 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
Yuri Ivann Cano
Yuri Ivann Cano
Posted Tuesday, September 18, 2012 5:23 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, November 09, 2012 10:59 AM
Points: 7,
Visits: 19
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
Lynn Pettis
Lynn Pettis
Posted Tuesday, September 18, 2012 5:44 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:50 PM
Points: 21,624,
Visits: 27,465
#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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.