Hi, can anyone help me with the following xp_cmdshell/osql problem?
To solve a problem with osql I use the two sql test-scripts. Script1 is
loaded in Sql Query Analyzer. Executing scripts 1: this calls en execute
script2, which prints a message to the output window. Quite simple.
My problem: this is functioning well on a my develop pc (Windows XP-Pro),
but is not functioning on a production server with Windows 2000 Server (SP4)
.
On this production machine, recently sql server 2000 SP3 has been installed,
and everything of sqlserver 2000 looks the same as on my develop pc under
XP-pro. The error reported is about the syntax usage of osql: "usage: osql
[-U login id] [-P password] [-S server]" and the all the rest of the option
s
..... So I should think it has something to do with the used syntax, but i
t
IS functioning on my develop pc!
I don't understand why these testscripts do work on my develop pc, and don't
on the production server. I guess it has something to do with either the
difference in OS, or a setting in the new sql installation on the production
server, but I can't find out the cause.
****************************************
**
Script1.sql:
DECLARE @.SqlPath sysname, @.SqlScript as sysname, @.Cmd sysname, @.CmdCpl
nvarchar(400), @.CmdAndPath sysname
SET @.Cmd = 'osql -S MyServer -d MyDb -Usa -PPwd -i'
SET @.SqlPath = 'C:\MyPathToScript2'
SET @.CmdAndPath = @.Cmd + @.SqlPath
SET @.SqlScript = 'Script2.sql'
SET @.CmdCpl = @.CmdAndPath + @.SqlScript
EXEC master..xp_cmdshell @.CmdCpl
****************************************
**
Script2.sql:
DECLARE @.Test varchar(255)
SET @.Test = 'Hello world'
PRINT @.Test
****************************************
**
Any suggestions are welcome,
Regards Coen.One possible cause is that @.CmdCpl contains whitespace in the prod
environment so the command line parameters are not parsed as expected. In
that case, you can enclose the path in double-quotes:
SET @.CmdCpl = '"' + @.CmdAndPath + @.SqlScript + '"'
If that isn't the problem, try printing the actual @.CmdCpl value and running
from the command line.
Hope this helps.
Dan Guzman
SQL Server MVP
"Coen" <cbusker@.newsgroups.microsoft.com> wrote in message
news:D4DCA3BF-E67B-437C-ADE1-9071EA673BCE@.microsoft.com...
> Hi, can anyone help me with the following xp_cmdshell/osql problem?
> To solve a problem with osql I use the two sql test-scripts. Script1 is
> loaded in Sql Query Analyzer. Executing scripts 1: this calls en execute
> script2, which prints a message to the output window. Quite simple.
> My problem: this is functioning well on a my develop pc (Windows XP-Pro),
> but is not functioning on a production server with Windows 2000 Server
> (SP4).
> On this production machine, recently sql server 2000 SP3 has been
> installed,
> and everything of sqlserver 2000 looks the same as on my develop pc under
> XP-pro. The error reported is about the syntax usage of osql: "usage: osql
> [-U login id] [-P password] [-S server]" and the all the rest of the
> options
> ..... So I should think it has something to do with the used syntax, but
> it
> IS functioning on my develop pc!
> I don't understand why these testscripts do work on my develop pc, and
> don't
> on the production server. I guess it has something to do with either the
> difference in OS, or a setting in the new sql installation on the
> production
> server, but I can't find out the cause.
> ****************************************
**
> Script1.sql:
> DECLARE @.SqlPath sysname, @.SqlScript as sysname, @.Cmd sysname, @.CmdCpl
> nvarchar(400), @.CmdAndPath sysname
> SET @.Cmd = 'osql -S MyServer -d MyDb -Usa -PPwd -i'
> SET @.SqlPath = 'C:\MyPathToScript2'
> SET @.CmdAndPath = @.Cmd + @.SqlPath
> SET @.SqlScript = 'Script2.sql'
> SET @.CmdCpl = @.CmdAndPath + @.SqlScript
> EXEC master..xp_cmdshell @.CmdCpl
> ****************************************
**
> Script2.sql:
> DECLARE @.Test varchar(255)
> SET @.Test = 'Hello world'
> PRINT @.Test
> ****************************************
**
> Any suggestions are welcome,
> Regards Coen.
>|||Dan, thank you for your help. Indeed the problem was caused by whitespaces,
so simple. The double quotes resolved the problem. Thank you for your
assistance.
Regards, Coen
"Dan Guzman" wrote:
> One possible cause is that @.CmdCpl contains whitespace in the prod
> environment so the command line parameters are not parsed as expected. In
> that case, you can enclose the path in double-quotes:
> SET @.CmdCpl = '"' + @.CmdAndPath + @.SqlScript + '"'
> If that isn't the problem, try printing the actual @.CmdCpl value and runni
ng
> from the command line.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Coen" <cbusker@.newsgroups.microsoft.com> wrote in message
> news:D4DCA3BF-E67B-437C-ADE1-9071EA673BCE@.microsoft.com...
>
>sql
No comments:
Post a Comment