SQL72007:语法检查失败“发生意外的文件结尾".批量附近: [英] SQL72007: The syntax check failed 'Unexpected end of file occurred.' in batch near :
问题描述
在 SSDT 项目中(使用 VS2017/VS2015,SSDT 版本 15.1.61702.140),我无法构建我的项目.编译器一直抱怨 PostDeploymentScript 中的 sql 语句(是的,我已将 BuildAction 属性设置为 PostDeploy).sql语句为:
In SSDT project (using VS2017/VS2015, SSDT version 15.1.61702.140), I cannot get my project to build. The compiler keeps complaining about the sql statement in my PostDeploymentScript (yes, I have set the BuildAction property to PostDeploy). The sql statement is:
if ('$(env)' = 'dvp')
BEGIN
PRINT 'creating users for dvp'
:r .\SecurityAdditions\usersdvp.sql
END
ELSE IF ('$(env)' = 'qat')
BEGIN
PRINT 'creating users for qat'
:r .\SecurityAdditions\usersqat.sql
END
实际的错误信息是:
D:\My\File\Path\PostDeploymentScript.sql (lineNum, col): Error: SQL72007:
The syntax check failed 'Unexpected end of file occurred.' in the batch near:
在最后一行(end)的错误消息中引用的行号.知道是什么原因造成的吗?
The line num referred in the error message in the last line (end). Any idea what's causing this?
推荐答案
显然问题是由于我引用的文件中的 GO
语句造成的.在 if else
块中包含 GO
语句是无效的.这里 是一篇解释这一点的文章.我能够通过从引用的文件中删除所有 GO
语句并将 if else
拆分为两个 if
来使其工作.
Apparently the problem was due to the GO
statements I had in the files I was referencing. Having GO
statements inside if else
block is invalid. Here is an article explaining that. I was able to get it work by removing all GO
statements from the referenced files and by splitting if else
to two if
.
IF ('$(env)' = 'dvp')
BEGIN
:R .\SecurityAdditions\UsersDVP.sql
END
IF ('$(env)' = 'qat')
BEGIN
:R .\SecurityAdditions\UsersQAT.sql
END
GO
这篇关于SQL72007:语法检查失败“发生意外的文件结尾".批量附近:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!