Sql-server – Sql Agent Cannot Find the File Specified

sql serversql-server-2008

I have a SQL 2008 Agent job with a single Operating system (CmdExec) step:

C:\Scripts\Script.cmd

Script.cmd runs a CS-Script.

If I run C:\Scripts\Script.cmd, everything appears fine – I get my expected logging output and echo %ERRORLEVEL% shows 0 afterwards.

When I run it through SqlAgent, though – I get my expected logging output and then

The system cannot find the file specified.  
Process Exit Code 1.  
The step failed.

The logging output is complete and correct, so it does run the batch file and the EXE that the batch file calls. The last thing the CS-Script does is:

Console.WriteLine("Exiting at 2009-09-22 16:10:32 with Status {0}", exitCode);
return (int)exitCode;

which is logged in the output, and in entirety.

What file can't it find?

Best Answer

Clearing CS-Script's cache did the trick. Procmon didn't really help, but did show hits to the user's cache folder in C:\Users\sql-agent-svc\AppData\Local\Temp\CSSCRIPT\Cache which prompted me to try clearing it.

Since it's a per-user cache, running CS-Script as an admin manually used a different cache which didn't have the issue.

As I understand it, the cache is only to avoid recompilation of an unchanged script - so it really shouldn't cause any issues. But, deleting it and letting CS-Script recreate it seems to have worked.