How do I correctly extract specific info from an sql error message number 547?
Info Required:
- Table Name
- Constraint Name
- Column Name
Code:
Try
....
Catch ex As System.Data.SqlClient.SqlException
If ex.Number = 547 Then
End If
End Try
Sample message:
UPDATE statement conflicted with COLUMN CHECK constraint
‘CK_Birthdate’. The conflict occurred in database ‘Northwind’, table
‘Employees’, column ‘BirthDate’.
There is no straight forward way of getting these pieces of information separately.
It all gets concatenated into the error message.
You can use
select * from sys.messages where message_id=547to see the various different language formats of the message that you would need to deal with in order to extract the constituent parts then perhaps use regular expressions with capturing groups based around this information.