2011-09-21 64 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集合不包含重要信息。 –