Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, July 31, 2019 8:57 PM
I used the Powershell script in the link https://gallery.technet.microsoft.com/scriptcenter/Import-Large-CSVs-into-SQL-216223d9#content to load a large csv file into a SQL Server table. However, I was getting the error, Exception calling "WriteToServer" with "1" argument(s): "The given ColumnMapping does not match up with any column in the source or destination."
I added the input parameters in the data table Add method in the for each below and it still did not work. Should I be specifying each column name instead as in the C# and VB example?
foreach ($column in $columns) {
$null = $datatable.Columns.Add($column, $column)
}
All replies (3)
Friday, August 2, 2019 7:42 AM ✅Answered | 1 vote
The error indicates that the column names in the CSV do not match the column names in your sql table. They must match. Check spelling and be sure there is a column in the target table for every column in the CSV.
Without a good understanding of PowerShell and SQLServer this script may be beyond your capabilities. It is an advanced technique. The authors approach demonstrates a method for loading extremely large file - in excess of 50000 records - and is not generally useful for loading smaller files.
The following script is easier to use for large files but requires installing the ACE drivers.
https://1drv.ms/u/s!AjiiPtIUqzK_gcsfsZSCf2gRsFXblw
The following script reads a CSV into a datable and then copies to a SQL table.
https://1drv.ms/u/s!AjiiPtIUqzK_gdZiamMi5IQ1ojKRtw
In both cases the SQL table must be available and it must match the column names in the CSV.
\(ツ)_/
Wednesday, July 31, 2019 11:10 PM
If you have questions about or an issue with a gallery script you should contact the author in the Q & A section of the gallery. I'm pretty sure Chrissy will try to help you if possible.
Live long and prosper!
(79,108,97,102|%{[char]$_})-join''
Thursday, August 1, 2019 1:24 PM
I have posted in the Q&A section of the gallery and awaiting a response. I noticed though she has not answered previous posts of others for the last few years unless she is directly corresponding with them.