【问题标题】:NAnt, sqlcmd.exe and error codesNAnt、sqlcmd.exe 和错误代码
【发布时间】:2010-09-02 08:05:27
【问题描述】:

我似乎无法让 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。

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

【问题讨论】:

    标签: nant sqlcmd


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      documentation for sqlcmd.exe 似乎表明您需要通过 -r 开关将错误发送到 Nant 用来检查错误的 stderr

      【讨论】:

      • 不幸的是,传递-r 1 似乎并没有改变命令的结果。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多