Finding culprit rows on constraint failure

constraints datatable sqlbulkcopy sql-server

Question

Any idea if it's possible to get a list of the trouble making rows in an INSERT/UPDATE statement when a constraint test fails?

I'm trying to insert data with an SQLBulkCopy object reading data from a DataTable, and when the constraint fails I have no way of telling which rows caused the issue. The DataTable is quite large, and is actually data from an XML file so I can't really run a SELECT statement against that source to find rows that match the constraint's selection criteria.

Thx!

Popular Answer

FYI Could not find a way to get this info from the framework, so built a helper class that can retrieve all the errors and related data rows when a SqlBulkCopy process fails. See here for details: http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=13789&aid=387465



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why