Unfortunately, BCP itself does not seem to support such operations.
But I have an idea. The outputString we get when the query succeeds and fails is different. We can judge whether an error has occurred based on its content.
If it is determined that an error has occurred, if it is not the first row of data errors, the outputString will contain "n rows copied".
string outputString = process.StandardOutput.ReadToEnd();
string errorString = process.StandardError.ReadToEnd();
var index = outputString.IndexOf("rows copied");
var rowNumber = outputString.Substring(index - 2, 1);
After we get the value of n, then the (n+1)th row is the wrong row, and we can use ADO.Net to get the data of that row.
Row_Number() Over (Order By id) As RowNum
Where RowNum = rowNumber+1
In this way, we can get the first error row, and then we can continue to execute the bcp command, but the sql can be modified to select * from table where id> x.
If it is the first line of error, the method is similar. According to the specific string to determine this is the case, query the first line.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Maybe you can be a bit more specific about what errors you are seeing? To wit, I can really map what you say to your command, but maybe I'm missing something.