2011-09-21 63 views
2

我有一個strored PROC,當與特定的一組中的參數,返回稱爲以下消息 -如何獲得通過返回的所有消息錯誤存儲過程:

Msg 4104, Level 16, State 1, Line 1 
The multi-part identifier "abc" could not be bound. 
Msg 4104, Level 16, State 1, Line 1 
The multi-part identifier "pqr" could not be bound. 
Msg 4104, Level 16, State 1, Line 1 
The multi-part identifier "xyz" could not be bound. 
Msg 207, Level 16, State 1, Line 1 
Invalid column name 'Name'. 
Msg 50000, Level 16, State 1, Procedure ErrorHandlerProc, Line 218 
Error Processing Request [ApplicationError] 

我感興趣的最後一行因爲該誤差是其中一個是要顯示給用戶

Error Processing Request [ApplicationError] 

然而,當我CATC SqlExceltion,該消息屬性只包含第一行即

The multi-part identifier "abc" could not be bound. 

如何獲取完整的錯誤並向用戶顯示。

請注意,我無法更改存儲的proc。

更新

SqlException.Errors集合只包含一個條目是由SP返回的第一道防線。 InnerException爲空,其他屬性如DataStackTrace不返回所需的信息。

+2

你能展示你的代碼和你的try/catch嗎?檢查catch中的異常對象的屬性,如stacktrace和InnerException –

+0

在調試過的sp中不應該有這些類型的錯誤。這些都與壞的語法有關,應該在用戶看到之前就解決。 – HLGEM

+0

@HLGEM - 同意。但是有時候你所能做的只是與你所擁有的一起工作:)。 –

回答

1

請檢查Errors-屬性SqlException。在那裏您應該找到一個SqlError對象的列表,其中包含來自底層提供者的所有消息。

+0

請查看問題中的更新。 Errors集合不包含重要信息。 –