SQLCMD Problem

  • Hi

    I am trying to automate a SQL Script to run against a number of instances.

    I am using the following batch file:

    FOR /F "tokens=1" %%a in ("SERVERLIST.txt")DO SQLCMD -S %%a -E -i test.sql -o results.txt

    When I run the script I get the following in a command prompt:

    C:\DAILYCHECKS>FOR /F "tokens=1" %a in ("SERVERLIST.TxT") DO SQLCMD -S %a -E -i

    test.sql -o results.txt

    C:\DAILYCHECKS>SQLCMD -S SERVERLIST.TxT -E -i test.sql -o results.txt

    When I look at the results file I get the following:

    HResult 0x35, Level 16, State 1

    Named Pipes Provider: Could not open a connection to SQL Server [53].

    Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections..

    Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

    The serverlist.txt only has one instance in it at the moment.

    I can connect to it by SQLCMD from the command line if I enter:

    SQLCMD -S Server\Instance

    I assume that the am a entering the incorrect SQLCMD paramaters.

    Does anyone know what I am doing wrong.

    Thanks in advance

    Chris

  • take out the " "

    FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]

    FOR /F ["options"] %variable IN ('string') DO command [command-parameters]

    FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

    for example

    FOR /F "tokens=1" %%a in (SERVERLIST.txt)DO SQLCMD -S %%a -E -i test.sql -o results.txt

  • This is a double post. It is under the SQL Server Newbies forum as well, posted there first.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

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

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