How to catch a specific SqlException error?
The SqlException has a Number property that you can check. For duplicate error the number is 2601. catch (SqlException e) { switch (e.Number) { case 2601: // Do something. break; default: throw; } } To get a list of all SQL errors from you server, try this: SELECT * FROM sysmessages Update This can now … Read more