Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAnt, sqlcmd.exe and error codes

Tags:

nant

sqlcmd

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=&quot;${Database.Name}&quot;" />
</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?

like image 427
ladenedge Avatar asked Dec 06 '25 09:12

ladenedge


1 Answers

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

like image 59
Strelok Avatar answered Dec 11 '25 08:12

Strelok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!