Submit SQL server job from webpage in ASP.NET, C#
void submitjob_corpalloc(string FY)
{
SqlConnection DbConn = new SqlConnection(ConnectionString);
SqlCommand ExecJob = new SqlCommand();
ExecJob.CommandType = System.Data.CommandType.StoredProcedure;
ExecJob.CommandText = "msdb.dbo.sp_start_job";
if (FY == "2020")
{
//ExecJob.Parameters.AddWithValue("@job_name", "RunbudgetRoutineMultiYr"); //SP_tblRunEtl_Job
//ExecJob.Parameters.AddWithValue("@job_name", "RunbudgetRoutineMultiYr"); //sp_etljob_2020
ExecJob.Parameters.AddWithValue("@job_name", "BudgetRoutine_2020");
ExecJob.Connection = DbConn; //assign the connection to the command.
using (DbConn)
{
DbConn.Open();
using (ExecJob)
{
ExecJob.ExecuteNonQuery();
}
}
}
No comments:
Post a Comment