0

I'm trying to create a batch file that will execute a sql script which will backup a database.

The script looks like this:

USE $(DatabaseName);  
DECLARE     @DBName varchar(50), 
            @DateLabel  varchar(50), 
            @FileName   varchar(300), 
            @TodayDate  datetime, 
            @BackupPath varchar(200)

SET @DBName = $(DatabaseName);              
SET     @BackupPath = $(FolderPath) + '\';

The batch file outputs this:

G:\Deployments>script_PFBC_ResourceFirstPortal.bat  
G:\Deployments>REM ECHO OFF  
G:\Deployments>SET outTime=10:41:12.46  
G:\Deployments>SET outTime=104112.46  
G:\Deployments>SET outTime=10411246  
G:\Deployments>SET outPath=PFBCdb_2013_22_01_10411246  
G:\Deployments>mkdir PFBCdb_2013_22_01_10411246  
G:\Deployments>cd PFBCdb_2013_22_01_10411246  
G:\Deployments\PFBCdb_2013_22_01_10411246>SET fullOutPath=G:\Deployments\PFBCdb_
2013_22_01_10411246  
G:\Deployments\PFBCdb_2013_22_01_10411246>CD..  
G:\Deployments>sqlcmd -i "backup.sql" -v DatabaseName=PFBC_ResourceFirstPortal FolderPath="G:\Deployments\PFBCdb_2013_22_01_10411246"  
Msg 102, Level 15, State 1, Server HDCVS-PFBC, Line 21
Incorrect syntax near 'G:'.

The last line of the batch file looks like this:

sqlcmd -i "backup.sql" -v DatabaseName="PFBC_ResourceFirstPortal" FolderPath="%fullOutPath%"
M Kenyon II
  • 4,136
  • 4
  • 46
  • 94

1 Answers1

0

The error message seems to be complaining about the fact you're referencing the G: drive.

Try entering the full server path instead. I find this always avoids confusion when dealing with batch files and sqlcmd.

\\servername\folder1\folder2\Deployments\...
Andi Mohr
  • 458
  • 1
  • 6
  • 22