Home>

WindowsServer2016 Standard
SQLServer14.0

Run as the following user: NT Service \ SQLSERVERAGENT. C: \ Windows \ system32>echo 2020/11/20 18: 03: 21.45  Start  1>EmgSampleJobOnRunning.txt Access is denied. .Process exit code 1. .Step failed


For one SQL Server job, I am trying to place one text file as proof that it is running.
This placement is going to be achieved by preparing a bat file in advance (D: \ bat \) and executing it in the first step of the job.
However, denying the access right will cause the job to be lost.

In addition, it has been confirmed that the bat file that is going to be executed via the job works safely by simply clicking W on Explorer.

In any case, to the folder where the bat file is placed = the folder where the text file to be created is also placed
The SQL Server agent account has been added to the Security tab as follows.


What is the reason why when I start the text file creation bat file via the job, it fails?

Contents of the running bat file
echo% date%% time%  Start >EmgSampleJobOnRunning.txt
  • Answer # 1

    Run as the following user: NT Service \ SQLSERVERAGENT.
    C: \ Windows \ system32>echo 2020/11/20 18: 03: 21.45 ★ Start ★ 1>EmgSampleJobOnRunning.txt
    Access denied. .Process exit code 1. .Step failed

    C: \ Windows \ system32 \ EmgSampleJobOnRunning.txtI'm trying to create a file calledC: \ Windows \ system32You cannot create a file there.

    If you want to write the file with the full path or create the file in the directory where the batch file is, then in that directorycdThen it would be good.

    cd/d% ~ dp0
    echo% date%% time% ★ Start ★>EmgSampleJobOnRunning.txt


    % 0With the batch file name.% ~ dp0With its drive name and directory name.

  • Answer # 2

    Do you give access to the target folder to the user who is running the SQL Server service?
    I think you don't have permission to access the batch file.
    Reference below
    SQL Server Error 5 Access is denied. (Note record)