Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:28:12+00:00 2026-06-16T15:28:12+00:00

I am trying to Invoke a SQL agent job from my C# Application. I

  • 0

I am trying to Invoke a SQL agent job from my C# Application.

I want to be able to.

  • On the Press of a button be able to Execute the Job.

But i also want to have some sort of message for when the job is finished running or fails.

The Below Code sampe from another Answer will not work for me as i need access to the local MSDB database.

private Dictionary<int, string> ExecutionStatusDictionary = new Dictionary<int, string>()
{
{0, "Not idle or suspended"},
{1, "Executing"},
{2, "Waiting for thread"},
{3, "Between retries"},
{4, "Idle"},
{5, "Suspended"},
{7, "Performing completion actions"}
};

public string GetStatus()
{
SqlConnection msdbConnection = new SqlConnection("Data Source=GACDTL01CR585M;Initial       Catalog=msdb;Integrated Security=SSPI");
System.Text.StringBuilder resultBuilder = new System.Text.StringBuilder();

try
{
    msdbConnection.Open();

    SqlCommand jobStatusCommand = msdbConnection.CreateCommand();

    jobStatusCommand.CommandType = CommandType.StoredProcedure;
    jobStatusCommand.CommandText = "sp_help_job";

    SqlParameter jobName = jobStatusCommand.Parameters.Add("@job_name", SqlDbType.VarChar);
    jobName.Direction = ParameterDirection.Input;
    jobName.Value = "LoadRegions";

    SqlParameter jobAspect = jobStatusCommand.Parameters.Add("@job_aspect", SqlDbType.VarChar);
    jobAspect.Direction = ParameterDirection.Input;
    jobAspect.Value = "JOB";

    SqlDataReader jobStatusReader = jobStatusCommand.ExecuteReader();

    while (jobStatusReader.Read())
    {
        resultBuilder.Append(string.Format("{0} {1}",
            jobStatusReader["name"].ToString(),
            ExecutionStatusDictionary[(int)jobStatusReader["current_execution_status"]]
        ));
    }
    jobStatusReader.Close();
}
finally
{
    msdbConnection.Close();
}

return resultBuilder.ToString();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:28:14+00:00Added an answer on June 16, 2026 at 3:28 pm

    Using ADO.NET is not appropriate for what you want to do.
    You should be using the SQL Server Management Objects API (SMO), which is preferred when doing administrative tasks this way.

    More exactly, you should have a look at SMO’s Job.Start method. There’s a sample in the article on how to use it.
    The Job class provides some events (such as SuccessAction) to notify you when the job is finished executing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to invoke a method from another class that means I want to
I'm currently trying to invoke a web service from a web application that I've
When I try to use the Invoke-Sqlcmd cmdlet from SQL Server 2008 to execute
I am trying to invoke a button click from inside a .cshtml file: <input
I am trying to invoke an ANT target from Windows (right-click) file context menu.
I'm trying to implement sqldependency in my vb.net application as per: http://www.dreamincode.net/forums/topic/156991-using-sqldependency-to-monitor-sql-database-changes/ I'm having
I am trying to invoke an internal method from a dynamically generated one. The
i am trying to connect with sql server 2008 using java connection string but
I am trying to update individual record in SQL table. So, I have DataGridView
Below is my shell script from which I am trying to invoke few hive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.