Friday, October 16, 2015

Scheduling SQL server job C# asp.net



void submitjob()
    {
        SqlConnection DbConn = new SqlConnection(ConnectionString);
        SqlCommand ExecJob = new SqlCommand();
        ExecJob.CommandType = CommandType.StoredProcedure;
        ExecJob.CommandText = "msdb.dbo.sp_start_job";
        ExecJob.Parameters.AddWithValue("@job_name", "Extract_Account_Data");
        ExecJob.Connection = DbConn; //assign the connection to the command.

        using (DbConn)
        {
            DbConn.Open();
            using (ExecJob)
            {
                ExecJob.ExecuteNonQuery();
            }
        }
    }

No comments: