Environment:
- SQL Server Agent Job Type: Operating System (CmdExec)
- Python Version: Python 3.13.1
- Script Location:
C:\Users\Kevin\Desktop\Scripts\test.py
Issue Description: I’m trying to execute a Python script via SQL Server Agent. The script is very simple and aims to create a text file (print.txt
) in the same directory as the script. Below are the details:
Python Script (test.py
):
with open("print.txt", "w") as file:
file.write("Hello, World!\n")
Job Step Command:
"C:\Program Files\Python313\python.exe" C:\Users\Kevin\Desktop\Scripts\test.py
When I run the job, it fails with the following error:
PermissionError: [Errno 13] Permission denied: 'print.txt'
What I’ve Tried:
- Verified that the
SQLSERVERAGENT
service is running under the NT Service\SQLSERVERAGENT
account.
- Assigned
Full Control
permissions to the NT Service\SQLSERVERAGENT
account for the C:\Users\Kevin\Desktop\Scripts
folder.
- Tested the script manually via Command Prompt (
cmd
) and it works without issues.
What additional permissions or configurations are needed to allow the SQL Server Agent to create files via a Python script? Could there be other constraints specific to the SQL Server Agent’s account that I might have missed?