?
Solved

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

Posted on 2008-06-22
3
Medium Priority
?
691 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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

777 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