March 19, 2014 at 8:18 am
Hello,
I would like to have a button when pushed trigger a SQL Job run. Below is my code, for some reason I get an error message that says, "ExecuteNonQuery: Connection property has not been initialized.".
Does anyone have any suggestions?
private void btnRunDataRefresh_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(WindowsFormsApplication1.Properties.Settings.Default.ConnectionString);
SqlCommand ExecJob = new SqlCommand();
ExecJob.CommandType = CommandType.StoredProcedure;
ExecJob.CommandText = "msdb.dbo.sp_start_job";
ExecJob.Parameters.AddWithValue("@job_name", "Job_Name");
using (cn)
{
cn.Open();
using (ExecJob)
{
ExecJob.ExecuteNonQuery();
}
}
Thank you in advance!
March 19, 2014 at 8:51 am
nevermind, I just realized I was missing: ExecJob.Connection = cn;
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy