0

First of all, I did check hundreds of previous posts but I still have a problem. I have a T-SQL cursor. And I want to run this cursor every 5 minutes. In order to do that I've made a *.bat file (sqlcmd -S DEAMON\SQLEXPRESS -i reminder_cursor.sql) that runs it. Batch file and cursor file are both in the same folder (f.e. sql_cursor) and they both have the same name (f.e. reminder_cursor.bat, reminder_cursor.sql). In taskschd is:

General tab

  • When running the task, use the following user account: SYSTEM don't want to see console window

  • run with the highest privileges ticked

  • run whether user is logged on or not ticked

Triggers tab

  • begin a task on a schedule
  • Daily
  • recur every 1 day
  • Repeat task every 5 min for duration indefinitely
  • Enabled ticked

Actions tab

  • Action: start a program
  • Program script has exact path to the bat file
  • Start in (Optional): has exact path to the folder where bat file is stored

When I run the same bat file manually, it works (every time). Next run time goes forward, but doesn't run batch.

user3529850
  • 1,632
  • 5
  • 32
  • 51
  • 1
    You always have to use full paths to avoid problems (what is the default directory), especially when you've changed the user to another user (lots of things change). Full specified paths solves all problems. But why not just schedule sqlcmd rather than indirectly via a batch. Use full paths. –  Apr 09 '16 at 21:21
  • @Ken White, actually yes, I do. I have express edition and there is some sort of technical difficulties: http://stackoverflow.com/questions/22103162/create-jobs-in-sql-server-express-edition – user3529850 Apr 09 '16 at 21:23
  • Fair enough. What @Noodles said, then. :-) – Ken White Apr 09 '16 at 21:25
  • @Noodles I am. In `Action` tab, under `Program/script`, there is: `C:\Users\bartek\Documents\sql_cursor\reminder_cursor.bat` and under `Start in: C:\Users\bartek\Documents\sql_cursor` – user3529850 Apr 09 '16 at 21:27
  • I meant in your batchfile. Partial paths are an aid to typing interactively which you aren't doing. So full path to sqlcmd (as System's `path` variable is likely to be different to yours) and full path to the SQL file (as you are likely to be in a different default directory). –  Apr 09 '16 at 21:30
  • Didn't work. I have put: `"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd" -S DEMON\SQLEXPRESS -i C:\Users\bartek\Documents\sql_cursor\reminder_cursor.sql`, when I run batch file manually, it worked. Weird thing is that 3 days ago it was working. It looks like it stopped after computer restart. But I didn't do anything so have no idea what's wrong. Is there anything else I can check ? – user3529850 Apr 09 '16 at 21:57
  • Weird. I've changed user from `SYSTEM` to `demon\bartek` (my account), and it's working fine. Big drawback that console windows flicker every 5 minutes. EDIT: I've put `SYSTEM` again, and it works too. Weird. – user3529850 Apr 09 '16 at 22:07
  • 1
    You can use `> c:\logfile` to read any errors. –  Apr 10 '16 at 02:24

0 Answers0