Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sqlcmd' is not recognized as an internal or external command Expand / Collapse
Author
Message
Posted Friday, August 23, 2013 8:47 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 3:32 AM
Points: 30, Visits: 205
Hi, Can you help me to solve my problem with my script. got an error "sqlcmd' is not recognized as an internal or external command" and below is the full script.


@title Database Backup
@color 0a

rem User to Pre or Post Batch Backup
@echo.
@echo Please select:
@echo 1. Pre-Batch Backup - DATABASE NAME PB
@echo 2. Post-Batch Backup - DATABASE NAME PB
@echo.
choice /C 12 /M "Backup Type :"
IF %ERRORLEVEL%==1 SET var3=Pre-DATABASE NAME-PB-FullBackup-
IF %ERRORLEVEL%==2 SET var3=Post-DATABASE NAME-PB-FullBackup-


rem Get the Batch Processing Day per backup type
@echo.
@echo Please select:
@echo 1. MWF - (Monday,Wednesday, Friday)
@echo 2. TTH - (Tuesday, Thurdsay)
@echo.
choice /C 12 /M "Backup ProcDay :"
IF %ERRORLEVEL%==1 SET var2=MWF
IF %ERRORLEVEL%==2 SET var2=TTH

rem Display Parameters before proceeding
@echo.
@echo ================================================
@echo Backup Parameters for your confirmation....
@echo ================================================
@echo Backup Type : %var3%
@echo Batch ProcDay: %var2%
@echo.
@echo.
choice /C YN /M "Are the parameters correct?"
IF %ERRORLEVEL%==1 SET proceed=Yes
IF %ERRORLEVEL%==2 SET proceed=No


if %proceed%==No (
@echo.
@echo Backup terminated...
@echo.
pause
exit
)


set bkpfilepath=H:\Backup\Full Backup\%var3%%var2%.bak



@echo ================================================
@echo Backing up DATABASE NAME Database. Please Wait....
@echo ================================================


sqlcmd -S SERVERNAME -U USERNAME -P PASSWORD -Q "BACKUP DATABASE [DATABASE NAME] TO DISK = N'%bkpfilepath%' WITH NOFORMAT, INIT, NAME = N'DATABASE NAME-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"

set /p var5= Database backup completed. Press any key to continue..
Post #1487852
Posted Friday, August 23, 2013 11:56 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 12:11 PM
Points: 442, Visits: 1,149
Looks like just a path issue. Is the account executing the script able to run sqlcmd from the context of the folder that holds the script file? (log on as script user, open cmd prompt, navigate to script folder, exec sqlcmd to see if it runs).

You may need to add the path to sqlcmd (and also ensure the file is installed) to that user's profile, or use the fill path to sqlcmd in your script.
For example, on my laptop, the command would be C:\mssql\DefaultInstance\100\Tools\Binn\sqlcmd.exe <...parameters...>




Eddie Wuerch
MCM: SQL
Post #1487965
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse