Hi,
I'm using OSQL with the -i option to run an SQL script. I'm also using
-o to save the output to a file. I'm invoking this OSQL command via
C++ code and would like to get the return code from the SQL script
back to the c++ code in case an error condition occurs.
OSQL help indicates using RAISERROR with state of 127 to return error
codes to the parent process. I've tried that but have not been able to
do this successfully. Any examples that anybody may have would be very
helpful.
There is also the -b option but that only returns 0 or 1.
Any help in retrieving the error code from the SQL script back from
OSQL would be very much appreciated.
Thanks,
Roopa
Have you tried something like this. This example set @.RC to -100 if table
XXXX doesn't exist. If XXXX does exist then @.RC is equal to 0.
declare @.cmd varchar(1000)
declare @.rc int
set @.rc = 0
set @.cmd = 'osql -E -Sdohdbolypr01 -Q"exit(select top 1 * from xxxx)"'
exec @.rc=master.dbo.xp_cmdshell @.cmd
print @.rc
----
-
Need SQL Server Examples check out my website
http://www.geocities.com/sqlserverexamples
"RT" <rotrived@.cisco.com> wrote in message
news:f9f22d93.0409211255.6492b029@.posting.google.c om...
> Hi,
> I'm using OSQL with the -i option to run an SQL script. I'm also using
> -o to save the output to a file. I'm invoking this OSQL command via
> C++ code and would like to get the return code from the SQL script
> back to the c++ code in case an error condition occurs.
> OSQL help indicates using RAISERROR with state of 127 to return error
> codes to the parent process. I've tried that but have not been able to
> do this successfully. Any examples that anybody may have would be very
> helpful.
> There is also the -b option but that only returns 0 or 1.
> Any help in retrieving the error code from the SQL script back from
> OSQL would be very much appreciated.
> Thanks,
> Roopa
|||This is not what I want to do.
I don't have a single command that I run thru osql. I have a bunch of
commands in an sql script which I'm invoking thru osql. The osql
command is not invoked via a batch file. Instead I call the SQLPrepare
and SQLExecute methods to actually execute the osql command which in
turn runs all the commands in the script file.
Thanks,
Roopa
"Gregory A. Larsen" <greg.larsen@.netzero.com> wrote in message news:<#8KmLPCoEHA.1776@.TK2MSFTNGP14.phx.gbl>...[vbcol=seagreen]
> Have you tried something like this. This example set @.RC to -100 if table
> XXXX doesn't exist. If XXXX does exist then @.RC is equal to 0.
> declare @.cmd varchar(1000)
> declare @.rc int
> set @.rc = 0
> set @.cmd = 'osql -E -Sdohdbolypr01 -Q"exit(select top 1 * from xxxx)"'
> exec @.rc=master.dbo.xp_cmdshell @.cmd
> print @.rc
> --
> ----
> ----
> -
> Need SQL Server Examples check out my website
> http://www.geocities.com/sqlserverexamples
>
> "RT" <rotrived@.cisco.com> wrote in message
> news:f9f22d93.0409211255.6492b029@.posting.google.c om...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment