3

当遇到错误时,我似乎无法让 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=&quot;${Database.Name}&quot;" />
</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。

当我缺少逗号时,有什么想法可以确保我的脚本中止吗?

4

2 回答 2

8

您是否尝试设置-b选项?ERRORLEVEL发生错误时将设置为 1。可以帮助南特做出决定。

于 2010-09-07T03:50:07.713 回答
1

sqlcmd.exe的文档似乎声明您需要传递-r开关以发送stderrNant 用来检查错误的错误。

于 2010-09-02T08:11:18.187 回答