代码之家  ›  专栏  ›  技术社区  ›  ladenedge

nant、sqlcmd.exe和错误代码

  •  2
  • ladenedge  · 技术社区  · 14 年前

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

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

    2 回复  |  直到 14 年前
        1
  •  7
  •   Strelok    14 年前

    你试过设置 -b 选择权?将设置 ERRORLEVEL 发生错误时为1。有助于南特做出决定。

        2
  •  1
  •   Martijn Laarman    14 年前

    这个 documentation for sqlcmd.exe 似乎是说你需要通过 -r 切换到将错误发送到 stderr 南特用来检查错误。