Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting duplicate key values from SQL Exception

Tags:

c#

sql-server

As you know SQL Server 2008+ gives us the courtesy of knowing what values are duplicate by saying

The duplicate key value is (foo, bar)

in the SqlException message. Normally I get these values by using a regex and getting the data between the parentheses' to show it to end user.

I'm wondering; is there a more elegant way to get those values?

like image 489
Sin5k4 Avatar asked Sep 20 '13 06:09

Sin5k4


1 Answers

Don't think there is an elegant way, I would handle it the way you do with RegEx.

like image 158
Anusha Avatar answered Nov 14 '22 15:11

Anusha