Task Scheduler Last Run Result (0x1) but task partially completes

Michael Mariaskin 20 Reputation points
2023-06-20T13:13:15.8366667+00:00

I'm having an odd issue. I have a scheduled task that runs as a service account nightly. The service account has the appropriate permissions in SQL and AD to execute Powershell and execute the stored procedures in the database. This task runs on the SQL server itself. The powershell, creates some files and executes a main stored procedure that launches other stored procedures. When the task is scheduled to run, it successfully creates the files and executes the main stored procedure. It appears it made it through about half of the first stored procedure in the main stored procedure that called it. Some of these stored procedures take several minutes to run (the entire routine takes about 10 minutes). It seems 0x1 is a permissions error, but the permissions are the same for every stored procedure and table involved in this routine. If I run it manually as the service account it completes successfully. It almost appears like it is timing out. Any ideas?

Windows for business | Windows Server | User experience | PowerShell
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,401 Reputation points
    2023-06-20T14:40:27.8133333+00:00

    As with any computer program, you need to have error handling and logging in your code so that when something bad happens, you will know what statement failed, and what error code you got. That is especially important for an unattended processes like a scheduled task where there is no interactive user who could see the command window and the script output.

    Start by adding a transcript to the script.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

    Add try/catch blocks and display key variables (processing steps) so that you know what the script is doing, and you don't have to guess.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.