Get Specific Info From SQL Error Message 547
How do I correctly extract specific info from an sql error message number 547?
- Table Name
- Constraint Name
- Column Name
Try .... Catch ex As System.Data.SqlClient.SqlException If ex.Number = 547 Then End If End Try
UPDATE statement conflicted with COLUMN CHECK constraint
‘CK_Birthdate’. The conflict occurred in database ‘Northwind’, table
‘Employees’, column ‘BirthDate’.
2 Solutions collect form web for “Get Specific Info From SQL Error Message 547”
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=547 to 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.
In addition to queries, here’s a powershell script which wraps the sys.messages queries.