Fariya Farhad
Fariya Farhad

Reputation: 33

Bat file to run a sql query on a schedule through Task Scheduler

I am trying to run a .sql script on a schedule. I have created a batch file to run the script. The script runs fine in sql server management studio and also when I run the batch file content through cmd.

Contents of the batch file:

sqlcmd -S omfmesql -U OMESRV -P orat -i "\\pvsrv-
fsr14\data\Projects\Stat_Table_Creation_unique.sql"

The sql script is supposed to update a stat table. When I run it though cmd and refresh the stat table, the numbers are updated. But when I run this batch file through Task Scheduler, the only action that seems to be performed is running C:\Windows\SYSTEM32\cmd.exe

The task is stated to be completed successfully but the sql query is just not run.

I am not too experienced with Task Scheduler. Any help here would be very much appreciated. Thanks!

Note: I am not intending to use SQL Server Agent

Upvotes: 0

Views: 7200

Answers (1)

rd_nielsen
rd_nielsen

Reputation: 2459

If you have not done so, you need to set the location in Task Scheduler (TS). In at least some versions of TS, this can only be done when you create a basic task, not from the more general "Create Task..." option. Ensure that all the paths in the batch file are absolute or are based in this location.

Upvotes: 2

Related Questions