NAnt、sqlcmd.exe 和错误代码

发布于 2024-09-17 08:31:29 字数 1221 浏览 5 评论 0原文

当遇到错误时,我似乎无法让 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。

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡风轻 2024-09-24 08:31:29

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

Did you try setting the -b option? That will set ERRORLEVEL to 1 when an error occurs. Could help Nant decide.

抱着落日 2024-09-24 08:31:29

sqlcmd.exe 的文档似乎指出您需要通过-r 开关将错误发送到 Nant 用于检查错误的 stderr

The documentation for sqlcmd.exe seems to state that you need to pass the -r switch to send errors to stderr which Nant uses to check for errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文