osql from batch file

  • Hello all,

    I am running the following osql from a Windows 2000 cmd batch file:

    osql -E -S %2 -d msdb -n -Q -i C:\JobStatus\%3\JobStatus.sql -b

    if not %errorlevel% 0 (echo An error has occured creating stored procedures!) & (goto :Exit)

    echo Stored procedures created.

    JobStatus.sql is a script file that creats stored procedures in the msdb.

    If the SQL Server is stopped, I would like to exit the script here, but I cannot seem to capture anything from osql to test in the script to see if it was able to connect or not.  I just get a "Server does not exist" message, that I think comes from ODBC and the script continues to execute.

    Any thoughts?

    Thanks

    Jonathan

     

     

  • crude but effective?

    for /F %%a in ('osql -S%2 -h-1 -n -E -Q"set nocount on select 1"') do if not "%%a"=="1" goto :Exit

    echo can connect

    :Exit

     

Viewing 2 posts - 1 through 2 (of 2 total)

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