Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Test that I can see database

Author  Topic 

Starting Member

9 Posts

Posted - 2007-05-16 : 15:16:16
I have a small batch file that will run all of the *.sql files in the same folder. My question is: is there a way to first test that I can see the DB so I can oputput an error if I cant?
Here is what I have so far:

@echo off
echo ++++++++++++++++++++
echo Runs all SQL scripts that do not require parameters within the
echo same folder as this batch file.
Echo ++++++++++++++++++++

SET ServerName=
SET /P ServerName=Please enter the Server Name:
SET DatabaseName=
SET /P DatabaseName=Please Enter Database Name:

REM IF I can connec to DB continue
REM ELSE goto :NoConn

for /f %%a in ('dir /b *.sql') do call :Process %%a
goto :Done

echo Running: %1
osql -E -S %ServerName% -d %DatabaseName% -n -i %1 > Report.txt

echo error cannot connect to Database.

echo Operation completed.


- Advertisement -