igor-tkachev/bltoolkit — Issue #59: Bug in DbManager InsertBatch when not using transaction
Author: yrozhkov
Created: 2011-10-18 21:28:00+00:00
State: open

in SqlDataProviderBase when using with ms sqlServer

public override int InsertBatch(
DbManager db,
string insertText,
IEnumerable collection,
MemberMapper[] members,
int maxBatchSize,
DbManager.ParameterProvider getParameters)
{
if (db.Transaction != null)
return base.InsertBatch(db, insertText, collection, members, maxBatchSize, getParameters);

var idx = insertText.IndexOf('\n');
var tbl = insertText.Substring(0, idx).Substring("INSERT INTO ".Length).TrimEnd('\r');
var rd = new BulkCopyReader(members, collection);
var bc = new SqlBulkCopy((SqlConnection)db.Connection)
{
BatchSize = maxBatchSize,
DestinationTableName = tbl,
};

bc.WriteToServer(rd);

return rd.Count;
}
bc.WriteToServer(rd) fails
Reason:
BulkCopyReader member collection indices are not aligned with SqlBulkCopy class metadata