2010-09-02 45 views
2

我似乎無法讓NAnt在遇到錯誤時放棄構建。這裏有很多sqlcmd.exe處決的一個: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

任何想法,以確保我的腳本中止時,我缺少一個逗號?

回答

7

你試過設置-b選項嗎?發生錯誤時,會將ERRORLEVEL設置爲1。可以幫助Nant做出決定。

+0

非常好,那就是訣竅。非常感謝! – ladenedge 2010-09-07 17:54:42

1

documentation for sqlcmd.exe似乎說明你需要通過-r開關發送錯誤到stderr Nant用來檢查錯誤。

+0

不幸的是,傳遞'-r 1'似乎沒有改變命令的結果。 – ladenedge 2010-09-02 10:40:12