?
Solved

Sql server error number is the same for "Forignkey" And "check Constraint"

Posted on 2008-06-22
3
Medium Priority
?
693 Views
Last Modified: 2009-12-16
Hello
am little confused , i know that errors in sql server has  A number code ,  but the problem is
the error Number is same in Foriegn Key Violation and in  conflicted with the CHECK constraint
both of them has the same error Number  547
so when i try to violate the foringn key constraint it comes with the error as following
Msg 547, Level 16, State 0
also when i try to confilct with check constraint i recieve the same error number
Msg 547, Level 16, State 0

My problem is these number is important for me because i use it form my vb.net app. to  handle the error and raise an friendly error message to the user
1-Can you help me and tell me why is this happen ?
2-Can you give me a link to all SQL server Errors numbers/code because i searched and i didnt find
0
Comment
Question by:ali_alannah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 21840204
>1-Can you help me and tell me why is this happen ?
 foreign key IS a check contraint.

>2-Can you give me a link to all SQL server Errors numbers/code because i searched and i didnt find
http://www.microsoft.com/technet/support/ee/ee_advanced.aspx

or, in sql server, you have the table sysmessages:
http://technet.microsoft.com/en-us/library/ms177546.aspx
0
 

Author Comment

by:ali_alannah
ID: 21841960
Hello angelIII:
You post very helpfull but Please guide me and tell mh if i want to diffretiate between Forigkn key violation and the Check constraint confilct , to raise a friendly error message to the user
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21842001
to differentiate, you have to check the error text/description.
which is "dangerous", as if ever the language setting of the login is changed, the text might change also.

now, with due respect:
is your project that advanced/complete that you have to "bother" such subtle differences in what exactly the user is reported as error message?
especially foreign key constraints should "never" be violated by a application, given the user only those choices that cannot violate the foreign key constraints ...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question