本文介绍了的SQLException约束冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个asp.net应用程序。
有没有一种方法,一个醒目的SQLException时,
知道哪些约束被侵犯?

I'm working on an asp.net app.Is there a way, when catching a SqlException, to know which constraint was violated?

推荐答案

的SQLException有SQLERROR对象的集合:Errors.该具有属性的错误的并可以与已知的约束违反错误编号(如:2627)进行比较。

SqlException has a collection of SqlError objects: Errors. The SqlError have properties for error Number and you can compare this with the known constraint violation error numbers (eg. 2627).

如果多个错误在一个批次发生,因此最好检查Errors集合虽然是事实,本身的SQLException公开了号码属性,它是不准确的。

While is true that SqlException itself exposes a Number property, it is not accurate if multiple errors happen in a single batch and hence is better to inspect the Errors collection.

这篇关于的SQLException约束冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:35