SqlBulkCopy ColumnMappings Mismatch

“The given ColumnMapping does not match up with any column in the source or destination”

This error caused me more head-scratching than it should have done today. I was using SqlBulkCopy to bulk insert some data into an SQL Server table from a .NET DataTable, something I’ve done before - it’s not rocket science. But I hit this error upon calling WriteToServer and it took me a while (longer than it should have done really!) to track down the problem. The ColumnMappings I’d specified, to map the data columns in my DataTable to the underlying database table columns, all seemed to tally up - each column did exist in the source DataTable and the destination SQL Server table. I was expecting that I’d made a stupid mistake and just couldn’t see the wood for the trees.

ColumnMappings are case-sensitive

The problem was because the name I’d given for the destination column name for one of the column mappings, did not match the case of the name of that column in the database. Once I’d eventually identified the problem (an “i” character should have been “I” to match exactly the database schema), it was a bit of a face-palm moment. I don’t see any reason why it should be case sensitive and believe it should not matter. A bit more digging led me to this open Microsoft Connect bug report from some years ago.

I won’t be tripping over this again!


See also