NAnt、sqlcmd.exe 和错误代码
当遇到错误时,我似乎无法让 NAnt 中止我的构建。这是许多 sqlcmd.exe 执行之一:
<property name="test" value=""/>
<exec program="sqlcmd.exe" resultproperty="test" failonerror="true"
basedir="${sqlcmd.dir}" commandline="${commandline.script}" verbose="true">
<arg value="${filename}" />
<arg value="-v databaseName="${Database.Name}"" />
</exec>
<echo message="Result: ${test}"/>
当我执行此步骤时,由于(在本例中)缺少逗号,我最终出现错误。输出如下:
[exec] Starting 'C:\...\sqlcmd.exe (-E -S (local) -e -d "Core"
-i "C:\...\Associations.sql" -v databaseName="Core")'
in 'C:\...\Scripts'
[exec] <snip - lots of SQL>
[exec] Msg 102, Level 15, State 1, Server <snip>, Line 7
[exec] Incorrect syntax near 'CreatedDate'.
[exec] Msg 319, Level 15, State 1, Server <snip>, Line 11
[exec] Incorrect syntax near the keyword 'with'. If this
statement is a common table expression, an xmlnamespaces
clause or a change tracking context clause, the previous
statement must be terminated with a semicolon.
[echo] Result: 0
相当令人讨厌的错误,但 sqlcmd.exe 似乎将返回代码设置为 0。
有什么想法可以确保我的脚本在缺少逗号时中止吗?
I can't seem to get NAnt to abort my build when it encounters an error. Here's one of many sqlcmd.exe executions:
<property name="test" value=""/>
<exec program="sqlcmd.exe" resultproperty="test" failonerror="true"
basedir="${sqlcmd.dir}" commandline="${commandline.script}" verbose="true">
<arg value="${filename}" />
<arg value="-v databaseName="${Database.Name}"" />
</exec>
<echo message="Result: ${test}"/>
When I hit this step, I end up with an error due to (in this case) a missing comma. Here's the output:
[exec] Starting 'C:\...\sqlcmd.exe (-E -S (local) -e -d "Core"
-i "C:\...\Associations.sql" -v databaseName="Core")'
in 'C:\...\Scripts'
[exec] <snip - lots of SQL>
[exec] Msg 102, Level 15, State 1, Server <snip>, Line 7
[exec] Incorrect syntax near 'CreatedDate'.
[exec] Msg 319, Level 15, State 1, Server <snip>, Line 11
[exec] Incorrect syntax near the keyword 'with'. If this
statement is a common table expression, an xmlnamespaces
clause or a change tracking context clause, the previous
statement must be terminated with a semicolon.
[echo] Result: 0
Pretty nasty error, and yet sqlcmd.exe appears to set the return code to 0.
Any ideas to make sure my script aborts when I'm missing a comma?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试设置
-b
选项?当发生错误时,会将ERRORLEVEL
设置为 1。可以帮助南特做出决定。Did you try setting the
-b
option? That will setERRORLEVEL
to 1 when an error occurs. Could help Nant decide.sqlcmd.exe 的文档似乎指出您需要通过
-r
开关将错误发送到 Nant 用于检查错误的stderr
。The documentation for sqlcmd.exe seems to state that you need to pass the
-r
switch to send errors tostderr
which Nant uses to check for errors.