Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColumnMappings #7

Open
jakedenyer opened this issue Nov 6, 2015 · 0 comments
Open

ColumnMappings #7

jakedenyer opened this issue Nov 6, 2015 · 0 comments

Comments

@jakedenyer
Copy link

Warren - was looking at this function and I noticed that the function is adding every single column to the column mappings even if you don't specify a ColumnMapping parameter. I'm actually going through some testing with this right now and I'm finding that with tables that have a large number of columns (the column number that failed in my case was 39) - the SqlBulkCopy object just doesn't like it.

In my case - what I was able to do to remediate this behavior was comment out the code in the else statement.

            if ( $PSBoundParameters.ContainsKey( 'ColumnMappings') -and        $ColumnMappings.ContainsKey($column) )
            {
                [void]$bulkCopy.ColumnMappings.Add($column,$ColumnMappings[$column])
            }
            else
            {
                #[void]$bulkCopy.ColumnMappings.Add($column,$column)
            }

With the SqlBulkCopy Object if you don't specify a Column Mapping it just goes through the Columns in order by default. This fixed the issue for me.

"If mappings are not defined—that is, the ColumnMappings collection is empty—the columns are mapped implicitly based on ordinal position. For this to work, source and target schemas must match. If they do not, an InvalidOperationException will be thrown."

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopycolumnmapping.aspx

A possible fix for the function would be a -DefaultColumnMapping switch or -NoColumnMapping (i dont know lol ) - just for special cases like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant