So I have a basic SQL agent job that runs a Robocopy script to move all files from one folder to another.

Job is a pretty basic set up. Enabled

With a pretty basic schedule.


And yet it has yet to run. I don't mean run successfully either I mean run at all. Is there any reason this might be the case?

For additional information I'll script out the job as well.

USE [msdb]

/****** Object:  Job [MoveMantisFilesToArchive]    Script Date: 12/23/2015 10:21:52 AM ******/
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]]    Script Date: 12/23/2015 10:21:52 AM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback


EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'MoveMantisFilesToArchive', 
        @description=N'Moves Mantis files to archive. It''s a very descriptive title.', 
        @category_name=N'[Uncategorized (Local)]', 
        @notify_email_operator_name=N'MyEmailGroup', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Move the files in the afformentioned title.]    Script Date: 12/23/2015 10:21:53 AM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Move the files in the afformentioned title.', 
        @os_run_priority=0, @subsystem=N'CmdExec', 
        @command=N'robocopy MySoruce MyDestination /mov', 
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'M-F', 
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
GOTO EndSave

  • Okay when It was originally set up it was running as the service account. It's since been changed to a different account and is running fine.
    – Zane
    Dec 23, 2015 at 17:34

1 Answer 1


Commentary on this question: Looking over this post I observe that your job was originally running as 'sa'. It appears that the service account for your SQL Server was not given rights to the necessary file shares.

This is apparently what led to the job looking as if it were "Running" forever. Of course, nothing was actually happening.

It is a best practice to withhold giving the SQL Server service account rights to any non-essential folders. This helps keep the SQL Server environment from being exploited for unsafe activities. (Much the same reason that the xp_cmdshell stored procedure is disabled by default.)

When you switched from sa to an account that had the needed rights to the file system everything worked. Which was, of course, the right thing to do.

Scheduled SQL Agent jobs do sometimes hang (but look like they are still 'running') for a long time. Likely this is usually due to external issues, such as not getting access to file system.

As long as the SQL Agent believes the job is "running", it will not try to start the job again.

Simple lessons:

  1. Think of 'sa' as ruling the SQL Server, but must beg for rights elsewhere.
  2. When reviewing SQL Agent job history, be alert to jobs that have been running much too long. That usually means that the SQL Agent does not realize that the process has died.
  3. Always plan to use a proxy account for SQL Agent jobs that need to access data or objects outside of the SQL Server. And make sure that the rights are granted to the Credential that the Proxy is using.

And, of course, every rule has exceptions.

  • TLDR: Wasn't paying attention and did something stupid.
    – Zane
    Jan 5, 2016 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.