SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Overriding error message sent back


Overriding error message sent back

Author
Message
xxx-593414
xxx-593414
Mr or Mrs. 500
Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)

Group: General Forum Members
Points: 573 Visits: 62
I have a table with a constraint on 2 columns (Which are keys into 2 other tables) and I want to prevent duplications
I am using Entity Framework and message sent back to application if violation is encountered
[1234,5678 ] is duplicated (i.e. It sends back the 2 keys that would be duplicated if I saved)
(e.g. I am adding a Country and a City to a third table, and want to prevent duplications where the same Country and City are attempted to be added)
e.g.
Country Table City Table
001 Ireland 100 Dublin
002 France 200 New York
003 USA 300 Paris
So if I try to add
Ireland Dublin
Ireland Dublin I get back [001,100] duplication error (I think this is Error Code 40005)

I'd prefer to get back
[Ireland, Dublin] Dupliction error attempted

I would prefer to send back, not the Primary Keys, which are meaningless, but two other columns of descriptions
Is this possible ?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (919K reputation)SSC Guru (919K reputation)SSC Guru (919K reputation)SSC Guru (919K reputation)SSC Guru (919K reputation)SSC Guru (919K reputation)SSC Guru (919K reputation)SSC Guru (919K reputation)

Group: General Forum Members
Points: 919250 Visits: 48849
If you're using Entity Framework, and it's running ad-hoc SQL against the DB, no. Handle the error in your application and present to the user something meaningful.
If you have a stored procedure, use TRY... CATCH and RAISERROR

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


xxx-593414
xxx-593414
Mr or Mrs. 500
Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)

Group: General Forum Members
Points: 573 Visits: 62
GilaMonster - Sunday, December 24, 2017 6:56 AM
If you're using Entity Framework, and it's running ad-hoc SQL against the DB, no. Handle the error in your application and present to the user something meaningful.
If you have a stored procedure, use TRY... CATCH and RAISERROR


Many thanks for your reply
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search