如何才能知道从SQL Server _exact_错误错误、SQL、Server

2023-09-02 02:01:12 作者:°我注定负你的 -

我在.NET应用程序。它更新一个SQL Server数据库。 一个异常。我怎么知道的完全的发生了什么事?

I have an application in .NET. It updates a SQL Server database. An exception is thrown. How do I know exactly what happened?

理解是,例如,是一个外键冲突没有任何问题。但是的这的外键。

Understanding that it, for instance, was a foreign key violation isn't any problem. But which foreign key is.

的说明文字(exception.Message)足以让我,作为一个人,因为它拥有(半)自由文本。但是,计算机不应该把自己降低到人类chitter喋喋不休。

The explaining text (exception.Message) is enough for me, as a human, since it holds (semi-) free text. But a computer shouldn't have to lower itself to human chitter chatter.

特别是因为错误消息可能SQL Server版本之间,绝对已安装的语言之间进行切换。 ......外键异常FK_Cust ...或...främmande·尼克尔undantag FK_Cust ......

Especially since the error message might change between SQL Server versions and absolutely between installed languages. "...foreign key exception FK_Cust..." or "...främmande nyckel undantag FK_Cust..."

有一个号码(仍从COM鼎盛时期?)映射到某一类的错误,但我还没有找到非常外键或索引,或者约束失败的计算机可以理解的方式。

There is a number (a remains from the COM heydays?) that maps to a certain class of error but I haven't found the very foreign key, or index, or constraint that failed in a computer understandable way.

推荐答案

您看的 SqlException.Errors 集合。每个 SQLERROR 集合中有一个号码。这个数字将是你的确切的错误。

You look at the SqlException.Errors collection. Each SqlError in the collection has a Number. That number will be your exact error.