In ADO, you'd access the connections Errors
property after an error occurs, and examine the NativeError
property to get the SQL Server specific error numbers.
When you switch to .NET, the same number is exposed as the Number
property of SqlException
or SqlError
However, finding the specific error numbers can be a bit of a chore - For Duplicate Key, it's error number 2627.