FastCoder
New member
- Joined
- May 19, 2022
- Messages
- 1
- Programming Experience
- 5-10
So I was running the following code:
And I got the following exception:
Now I am trying to determine what column is causing this problem. So after researching, I came across this site: Received Invalid Column Length from bcp Client for Volid N
Now I wrapped the above code into a try catch block:
Now, where I am stuck at this point is how to replace the BulkCopy. So what I would like to do is to clearly define the exception and find out what column/value is causing the problem. Any help is greatly appreciated.
Thanks in advance
C#:
await _internalDb.BulkInsertOrUpdateAsync(results, bulkConfig, (progress) =>
{
log.BulkUpsertProgress(progress);
});
Received an invalid column length from the bcp client for colid 4
Now I am trying to determine what column is causing this problem. So after researching, I came across this site: Received Invalid Column Length from bcp Client for Volid N
Now I wrapped the above code into a try catch block:
C#:
try
{
await _internalDb.BulkInsertOrUpdateAsync(results, bulkConfig, (progress) =>
{
log.BulkUpsertProgress(progress);
});
}
catch (Exception ex)
{
string message = string.Empty;
if (ex.Message.Contains("Received an invalid column length from the bcp client for colid"))
{
string pattern = @"\d+";
Match match = Regex.Match(ex.Message.ToString(), pattern);
var index = Convert.ToInt32(match.Value) - 1;
FieldInfo fi = typeof(SqlBulkCopy).GetField("_sortedColumnMappings", BindingFlags.NonPublic | BindingFlags.Instance);
var sortedColumns = fi.GetValue(bulkcopy);
var items = (Object[])sortedColumns.GetType().GetField("_items", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sortedColumns);
FieldInfo itemdata = items[index].GetType().GetField("_metadata", BindingFlags.NonPublic | BindingFlags.Instance);
var metadata = itemdata.GetValue(items[index]);
var column = metadata.GetType().GetField("column", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(metadata);
var length = metadata.GetType().GetField("length", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(metadata);
message = (String.Format("Column: {0} contains data with a length greater than: {1}", column, length));
}
return message;
}
Thanks in advance
Last edited by a moderator: