Re: Returning error codes from OSQL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: RT (rotrived_at_cisco.com)
Date: 09/22/04


Date: 22 Sep 2004 15:22:01 -0700

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>...
> 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.com...
> > 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



Relevant Pages

  • Re: How do I import/export databases in MSDE?
    ... What originally screwed me up in OSQL was that is wasn't clear that the ... commands were batched and that one must issue a "GO" command. ... > the detach/attach technique works different, and requires you to detach the ... > transaction log file) to the destination server, ...
    (microsoft.public.sqlserver.msde)
  • Re: Cannot Install DB
    ... Thats got it..with the OSQL -E it worked fine thru cmd.. ... > So perhaps you are not connected to the MSDE rathjer than to a SQL Server. ... > this on the command line: ... >>> HTH, Jens Suessmeyer. ...
    (microsoft.public.sqlserver.msde)
  • Changing SA password
    ... After typing "osql -U sa" at the ... command prompt the following message appears "'osql' is ... professional and trying to load MSDE 2000. ... open the command prompt window. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: exporting sql queries
    ... A usual technique is to run the script through OSQL, either from the command ... settings that control how your results are presented, e.g. header line, no ... > is there a way to export the results of query to a text file using t-sql ...
    (microsoft.public.sqlserver.programming)
  • Re: running an .sql script from an asp.net web page
    ... Bruce Barker wrote: ... > i doubt if they allow osql, as this would require their sqlsever to ... > sql script page- post a file, ... >> CREATE DATABASE IBuyAdventure ...
    (microsoft.public.dotnet.framework.aspnet)