批处理文件sqlcmd到备份数据库失败

时间:2013-01-22 15:50:53

标签: batch-file sqlcmd

我正在尝试创建一个批处理文件,该文件将执行将备份数据库的sql脚本。

脚本如下所示:

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

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

批处理文件输出:

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:'.

批处理文件的最后一行如下所示:

sqlcmd -i "backup.sql" -v DatabaseName="PFBC_ResourceFirstPortal" FolderPath="%fullOutPath%"

1 个答案:

答案 0 :(得分:0)

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

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

\\servername\folder1\folder2\Deployments\...