zzzprojects/Dapper-Plus

Received an invalid column length from the bcp client for colid

Zero-Xiong opened this issue · 3 comments

Get exception when use BulkInsert, the error message is

Received an invalid column length from the bcp client for colid N (N is number)

Code example:

var sb = new StringBuilder();
var resultInfoInsert = new Z.BulkOperations.ResultInfo();
DapperPlusManager.Entity("insert_key").Table("tablename")
.Key(k => new { k.col1, k.col2, k.col3 })
.UseBulkOptions(option =>
{
option.UseLogDump = true;
option.LogDump = sb;
option.Log = s => Console.WriteLine(s);
option.UseRowsAffected = true;
option.ResultInfo = resultInfoInsert;
})
.Ignore(i => new { i.ignore1, i.ignore2 })
.InsertIfNotExists();

db.BulkInsert("insert_key", records);

Further technical details

  • Dapper version: 2.0.123
  • Dapper Plus version: 4.0.39
  • Database Provider: MS Sql server 2019 Standard

Hello @Zero-Xiong ,

This issue normally happens when one of your values is greater than the size in your database.

There are 3 options:

  • Increase your database column size
  • Ensure on your side that all your string length is equal or less than the database column size
  • Use the AutoTruncate = true option that will ensure all your string length is equal or less than the database column size (however, as you can understand, it will truncate the string value)

Let me know if that explains the cause and solution of this issue correctly.

Best Regards,

Jon

Hello @Zero-Xiong ,

Since our last conversation, we haven't heard from you.

Let me know if one of the solutions proposed solved your issue.

Best regards,

Jon

Hello again!

A simple reminder that we are here to assist you.

Don't hesitate to contact us if you need further assistance.

Best regards,

Jon