c# - Using SMO.Agent to retrieve SQL job execution status - security issue -
I have a C # program that uses jobs (SMO) to shut down jobs, something looks like this:
server ssis_server = new server (new server connection (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 (); Onsut ("Job Started:" + job_name); } Else {OnError ("The job is already running or not ready."); }
I am using this point to simplify things as long as I work on it.
Now, my problem is that until SERVER_USERNAME
is part of the 'Sysadmin' dbo role, ssis_job.CurrentRunStatus
is always' inactive
'- Even when I know that the job is going on. This does not give an error, just always reports useless.
If the user is an administrator, then the situation has been returned in the expected form
Role membership that you say?
Well, I've added the SERVER_USERNAME
SQL Server login to the MSDB Roll SQL EGG Operator role, which was not helpful.
The job owner is a system administrator account - if this is a problem then I am not sure how to work around it.
Any thoughts?
Before you check the status, you will have to refresh the job by calling the refresh () method on ssis_job, then You will find the right information.
Comments
Post a Comment