Using SMO.Agent to Get SQL Job Execution Status - Security Issue

I have a C # program that launches SQL Server Agent using SQL Server Management Objects (SMO). It looks something like this:

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.");
}

I am using SQL Server Authentication at this point to simplify while I do this.

Now my problem is that if it SERVER_USERNAMEis part of the "sysadmin" dbo role, ssis_job.CurrentRunStatusalways " Idle" - even when I know that the work is being done. It does not give an error, it just always reports downtime.
If the user is an administrator, the status is returned as expected.

, ?
, SERVER_USERNAME SQL Server msdb SQLAgentOperatorRole, , , .
- - , , .

?

+5
1

, Refresh() ssis_job, , .

+3

All Articles