Home All Groups Group Topic Archive Search About

OSQL Batch File Problem

Author
22 Aug 2006 12:27 PM
J. Baez
I have a scheduled task that runs a batch file in windows 2003 server which
is running SQL Server 2000 Enterprise.

The batch file contains the line:

OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log

the 'myscript.sql' file updates a table with another table of the exact
number of rows.

When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
affected.

If I run this myself from the command line, 22,000 rows are affected which
is correct.

I am guessing there is some sort of permission/authentication issue here.  I
am sending the right username/password for SQL and for windows to run the
task.

Any idea what I could do to fix this?

Thanks,

J. Baez

Author
22 Aug 2006 12:42 PM
Hari Prasad
Hi,

Looks OS user have some perminssion issue. Try scheduling this job using SQL
Agent .. Jobs.

Thanks
Hari
SQL Server MVP


Show quote
"J. Baez" <JB***@discussions.microsoft.com> wrote in message
news:D02BC85F-20F3-44C3-B381-B71822BDF219@microsoft.com...
>I have a scheduled task that runs a batch file in windows 2003 server which
> is running SQL Server 2000 Enterprise.
>
> The batch file contains the line:
>
> OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log
>
> the 'myscript.sql' file updates a table with another table of the exact
> number of rows.
>
> When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
> affected.
>
> If I run this myself from the command line, 22,000 rows are affected which
> is correct.
>
> I am guessing there is some sort of permission/authentication issue here.
> I
> am sending the right username/password for SQL and for windows to run the
> task.
>
> Any idea what I could do to fix this?
>
> Thanks,
>
> J. Baez
>
Author
22 Aug 2006 12:50 PM
Roy Harvey
One thing I noticed was the server parameter, -Slocalhost.  That
sounds like it means local to where OSQL is running.  It is not clear
from your description that when you run it manually from the command
line you are on the same server as where the scheduled tasks run.

Roy Harvey
Beacon Falls, CT

On Tue, 22 Aug 2006 05:27:01 -0700, J. Baez
<JB***@discussions.microsoft.com> wrote:

Show quote
>I have a scheduled task that runs a batch file in windows 2003 server which
>is running SQL Server 2000 Enterprise.
>
>The batch file contains the line:
>
>OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log
>
>the 'myscript.sql' file updates a table with another table of the exact
>number of rows.
>
>When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
>affected.
>
>If I run this myself from the command line, 22,000 rows are affected which
>is correct.
>
>I am guessing there is some sort of permission/authentication issue here.  I
>am sending the right username/password for SQL and for windows to run the
>task.
>
>Any idea what I could do to fix this?
>
>Thanks,
>
>J. Baez
Author
22 Aug 2006 1:20 PM
J. Baez
yes, it is local to where OSQL is running.  Everything is being run on the
same windows server that has the scheduled tasks, MS SQL server and OSQL.

Show quote
"Roy Harvey" wrote:

> One thing I noticed was the server parameter, -Slocalhost.  That
> sounds like it means local to where OSQL is running.  It is not clear
> from your description that when you run it manually from the command
> line you are on the same server as where the scheduled tasks run.
>
> Roy Harvey
> Beacon Falls, CT
>
> On Tue, 22 Aug 2006 05:27:01 -0700, J. Baez
> <JB***@discussions.microsoft.com> wrote:
>
> >I have a scheduled task that runs a batch file in windows 2003 server which
> >is running SQL Server 2000 Enterprise.
> >
> >The batch file contains the line:
> >
> >OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log
> >
> >the 'myscript.sql' file updates a table with another table of the exact
> >number of rows.
> >
> >When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
> >affected.
> >
> >If I run this myself from the command line, 22,000 rows are affected which
> >is correct.
> >
> >I am guessing there is some sort of permission/authentication issue here.  I
> >am sending the right username/password for SQL and for windows to run the
> >task.
> >
> >Any idea what I could do to fix this?
> >
> >Thanks,
> >
> >J. Baez
>
Author
22 Aug 2006 10:37 PM
Erland Sommarskog
J. Baez (JB***@discussions.microsoft.com) writes:
Show quote
> I have a scheduled task that runs a batch file in windows 2003 server
> which is running SQL Server 2000 Enterprise.
>
> The batch file contains the line:
>
> OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log
>
> the 'myscript.sql' file updates a table with another table of the exact
> number of rows.
>
> When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
> affected.
>
> If I run this myself from the command line, 22,000 rows are affected which
> is correct.
>
> I am guessing there is some sort of permission/authentication issue
> here.  I am sending the right username/password for SQL and for windows
> to run the task.

No, permissions have nothing to do with it. Then you woould get an error.

I would suggest that you add a SELECT @@servername to the script. Like
Roy I'm suspicious of that -S parameter.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
10 Oct 2006 5:28 AM
Kartik
Hi,

         I have scheduled a job,in which i am porting the dat  of whole day
work by using on SP .It takes 10-11 Hrs. and sometimes it fails, while whenmi
execute that SP from Quey analyzer it takes only 10-11 Min.

Any suggesation for that JOb,so that it would'nt fail in future.

Sanjay

AddThis Social Bookmark Button