title: Using SMO.Agent to retrieve SQL job execution status - security issue
body: <p>I've got a C# program that fires off <a href="http://en.wikipedia.org/wiki/SQL_Server_Agent" rel="nofollow noreferrer">SQL Server Agent</a> jobs using the <a href="http://en.wikipedia.org/wiki/SQL_Server_Management_Objects" rel="nofollow noreferrer">SQL Server Management Objects</a> (SMO) interfaces. It looks something like:</p>
  
  <pre><code>Server ssis_server = new Server(
      new ServerConnection(SERVER_NAME, SERVER_USERNAME, SERVER_PASSWORD)
  );
  
  var agent = ssis_server.JobServer;
  var ssis_job = agent.Jobs[job_name];
  
  var current_status = ssis_job.CurrentRunStatus;
  
  if (current_status == JobExecutionStatus.Idle)
  {
      ssis_job.Start();
      OnSuccess("Job started: " + job_name);
  }
  else
  {
      OnError("Job is already running or is not ready.");
  }
  </code></pre>
  
  <p>I'm using <a href="http://msdn.microsoft.com/en-us/library/aa905171%28v=sql.80%29.aspx" rel="nofollow noreferrer">SQL Server Authentication</a> at this point to simplfy things whilst I work this out.</p>
  
  <p>Now, my problem is that unless the <code>SERVER_USERNAME</code> is part of the 'sysadmin' dbo role, <code>ssis_job.CurrentRunStatus</code> is always '<code>Idle</code>' - even when I know the job is running. It doesn't error out, just always reports idle.<br>
  If the user is an administrator, then the status is returned as expected. </p>
  
  <p>Role membership you say?<br>
  Well, I added the <code>SERVER_USERNAME</code> SQL Server login to the msdb Role SQLAgentOperatorRole, that didn't seem to help.<br>
  The job's owner is a system administrator account - if that's the issue I'm not sure how to work around it.</p>
  
  <p>Any ideas? </p>