当遇到错误时,我似乎无法让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.
当我错过逗号时,是否有任何想法确保我的脚本中止?
答案 0 :(得分:7)
您是否尝试设置-b
选项?发生错误时,这会将ERRORLEVEL
设置为1。可以帮助Nant决定。
答案 1 :(得分:1)
documentation for sqlcmd.exe似乎表示您需要通过-r
开关向Nant用于检查错误的stderr
发送错误。