@@ -547,6 +547,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
547
547
548
548
HashSet < string > destColumnNames = new HashSet < string > ( ) ;
549
549
550
+ Dictionary < string , bool > columnMappingStatusLookup = new Dictionary < string , bool > ( ) ;
550
551
// Loop over the metadata for each column
551
552
_SqlMetaDataSet metaDataSet = internalResults [ MetaDataResultId ] . MetaData ;
552
553
_sortedColumnMappings = new List < _ColumnMapping > ( metaDataSet . Length ) ;
@@ -569,9 +570,16 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
569
570
int assocId ;
570
571
for ( assocId = 0 ; assocId < _localColumnMappings . Count ; assocId ++ )
571
572
{
573
+ if ( ! columnMappingStatusLookup . ContainsKey ( _localColumnMappings [ assocId ] . DestinationColumn ) )
574
+ {
575
+ columnMappingStatusLookup . Add ( _localColumnMappings [ assocId ] . DestinationColumn , false ) ;
576
+ }
577
+
572
578
if ( ( _localColumnMappings [ assocId ] . _destinationColumnOrdinal == metadata . ordinal ) ||
573
579
( UnquotedName ( _localColumnMappings [ assocId ] . _destinationColumnName ) == metadata . column ) )
574
580
{
581
+ columnMappingStatusLookup [ _localColumnMappings [ assocId ] . DestinationColumn ] = true ;
582
+
575
583
if ( rejectColumn )
576
584
{
577
585
nrejected ++ ; // Count matched columns only
@@ -703,6 +711,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
703
711
break ;
704
712
}
705
713
}
714
+
706
715
if ( assocId == _localColumnMappings . Count )
707
716
{
708
717
// Remove metadata for unmatched columns
@@ -713,7 +722,17 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
713
722
// All columnmappings should have matched up
714
723
if ( nmatched + nrejected != _localColumnMappings . Count )
715
724
{
716
- throw ( SQL . BulkLoadNonMatchingColumnMapping ( ) ) ;
725
+ List < string > unmatchedColumns = new List < string > ( ) ;
726
+
727
+ foreach ( KeyValuePair < string , bool > keyValuePair in columnMappingStatusLookup )
728
+ {
729
+ if ( ! keyValuePair . Value )
730
+ {
731
+ unmatchedColumns . Add ( keyValuePair . Key ) ;
732
+ }
733
+ }
734
+
735
+ throw SQL . BulkLoadNonMatchingColumnName ( unmatchedColumns ) ;
717
736
}
718
737
719
738
updateBulkCommandText . Append ( ")" ) ;
0 commit comments