Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlBulkCopy exception, find the colid

Using SqlBulkCopy and getting this exception:

Received an invalid column length from the bcp client for colid 30.

I've been banging my head against this one for hours. I know what row is having the issue, but I don't know which column "colid 30" is. There are 178 columns in the data table. All values seem to be correct and I don't see any that are longer than any column data types in my database.

This database holds property listings and currently has over 3 million records, all of which are just fine.

Is there a way to pinpoint what colid 30 is? Or is there a way to view the actual SQL that the bcp is submitting to the database?

like image 316
Ricketts Avatar asked Feb 22 '26 21:02

Ricketts


1 Answers

I hope this helps solve someone else's issues as well.

The error was because one of the string/varchar fields in the datatable had a semicolon ";" in it's value. Apparently you need to manually escape these before doing the insert!

I did a loop through all rows/columns and did:

string.Replace(";", "CHAR(59)");

After that, everything inserted smoothly.

like image 62
Ricketts Avatar answered Feb 24 '26 10:02

Ricketts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!