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'