sqlcmd' is not recognized as an internal or external command

  • Am trying to run the below batch but I always get sqlcmd' is not recognized as an internal or external command,\roperable program or batch file . how to fix it please I have sql 2014

    @echo off

    set Instance=%1

    set DataBase=%2

    set Password=%3

    set userName=%4

    set path=%5

    set scripts=%path%\_scripts.txt

    if "%instance%" equ "" set instance=-"."

    if "%DataBase%" equ "" set DataBase=-"PracticeMaster"

    if "%Password%" equ "" set Password=-"123"

    if "%userName%" equ "" set userName=-"sa"

    rem

    rem Make sure the scripts file exists.

    rem

    if not exist %scripts% (

    echo.

    echo Scripts file "%scripts%" does not exist.

    echo.

    goto error

    )

    rem

    rem Clean output of any previous runs

    rem

    if exist %path%\__tmp* del /q %~dp0\__tmp*

    rem

    rem Apply all SQL scripts in order as listed in _scripts.txt

    rem

    rem NOTE: if any of the script filenames contain a space, this

    rem for loop will only see the 1st component of the filename,

    rem and then fail (file not found). Do not use spaces in the

    rem script filename.

    rem

    for /f "delims==" %%x in (%scripts%) do (

    echo.

    echo Applying script %path%\%%x...

    rem

    rem Make sure script exists

    rem

    if not exist "%path%\%%x" (

    echo.

    echo ERROR: script does not exist '%path%\%%x'

    echo.

    goto error

    )

    rem

    rem Run the script, show the output on stdout and tee this to a

    rem file with the same name as the script, prefixed with __tmp_

    rem

    sqlcmd -S %instance% -U %userName% -P %Password% -i "%path%\%%x" -o "%path%\__tmp_%%x.txt"

    )

    echo.

    echo Done!

    goto end

    :error

    echo.

    endlocal

    exit /b 1

    :end

    endlocal

    exit /b 0

  • Do you still get the error if you specify the path to the executable in your batch file?

    John

  • yes same issue

  • Please post your amended script. What happens if you run the command from a command line instead of within the batch file? Obviously you'll need to substitute parameters for actual values when you try that.

    John

  • John Mitchell-245523 (6/30/2016)


    Please post your amended script. What happens if you run the command from a command line instead of within the batch file? Obviously you'll need to substitute parameters for actual values when you try that.

    John

    I tried sqlcmd -S . -U sa -P 123 -i "C:\Temp\Plugin\SQL\script.sql and gave the same error

  • No, the path to the executable - something like this:

    "C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe" -S . -U sa -P 123 -i "C:\Temp\Plugin\SQL\script.sql

    John

  • Also note how John put quotes around the whole path and filename of the executable. While you're looking at it, don't forget to close the quotes around your script path/filename.

    As for the problem, you do have SQL Server installed on the machine where you're trying to run the command, right?

Viewing 7 posts - 1 through 6 (of 6 total)

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