如何才能知道从SQL Server _exact_错误 [英] How do I find out the _exact_ error from SQL Server

查看:121
本文介绍了如何才能知道从SQL Server _exact_错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.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 集合中有一个<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlerror.number.aspx相对=nofollow>号码。这个数字将是你的确切的错误。

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

这篇关于如何才能知道从SQL Server _exact_错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆