Windows scheduled tasks for OSQL

  • I want to set up a Windows scheduled task to run an OSQL command within a batch file.

    My problem is that I do not know what the minimum permissions are in order to allow me to do this.

    I can make the windows user that the task runs under an administrator and everything works fine, but when I use anything less the job simply says "Cannot start".

    The annoying thing is that if I login as the user that the scheduled task should run as I can run the actual batch file that the scheduled task is supposed to run.

    Any help would be gratefully received.

  • - Any drivemapping involved ? use UNC in stead of drive-letters.

    - capture your output

        --> for the batch for osql use the -o parameter (check bol)

        --> for dos maybe the >c:\myoutput.txt can help

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • No, there is no drive mapping involved. It is simply a case of writing to a local directory.

    I have tried right-clicking on the scheduled job and adding my intended user then giving them read/execute permisions but this doesn't allow the job to start.

    It is one of those situations where I wish Windows gave some useful feedback over and above "Cannot start job" such as "because....."

  • Just a wild shot :

    What (type of) account is serving Scheduled Task ?  Maybe it does not have the authority to access the batch or osql

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • ultimately the osql command is going to connect to sql server .  You can connect as sql authenticated login or windows authentcated login using the -U or -E  switches respectively.  -U requires you specify a sql auth login and password that is defined within SQL Server.  The -E switch will connect to SQL Server using the context of the current Windows login and again this windows login needs to be defined as a login within SQL Server. 

     

     Once connected to sql server the privileges of either login and what databases and objects the login can access is dictated by database user permissions. You need to grant permissions as required depending on what the script you are running from the osql session is trying to do.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply