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%"
4

1 回答 1

0

错误消息似乎在抱怨您引用 G: 驱动器的事实。

请尝试输入完整的服务器路径。我发现这在处理批处理文件和 sqlcmd 时总是可以避免混淆。

\\servername\folder1\folder2\Deployments\...
于 2013-01-22T16:05:48.653 回答