billgraziano / CsvDataReader

Fast streaming CSV file reader for PowerShell impleted as a DataReader.
40 stars 22 forks source link

Exception about column mapping #14

Closed andyseubert closed 5 years ago

andyseubert commented 5 years ago

Exception calling "WriteToServer" with "1" argument(s): "The given ColumnMapping does not match up with any column in the source or destination."

What am I missing here?

billgraziano commented 5 years ago

It's hard to know for sure without seeing the code. Did you add a custom column mapping? Is there a typo in a column name?

andyseubert commented 5 years ago

I get an error when I try to do this $bulkCopy.ColumnMappings.Add("tstamp", "hostname","loglevel","mid","dcid","icid","to","from","subject","logtext") | Out-Null the error: Cannot find an overload for "Add" and the argument count: "10".

I couldn't find documentation on how to format the column names or specify them. I get the same error below whether or not I add a column header row to my csv. Here is the code I'm trying. ``$ConnectionString='Server=tcp:sdb.domainname.com, 1433;Database=inventorydb;password=xxxxxx;uid=xxxxxx'

[System.Reflection.Assembly]::LoadFrom("C:\src\trunk\CsvDataReader.dll") | Out-Null $reader = New-Object SqlUtilities.CsvDataReader("$localTempCSV")

$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $ConnectionString $bulkCopy.DestinationTableName = "mail_logs" $bulkCopy.WriteToServer($reader) $reader.Close(); $reader.Dispose(); ``

andyseubert commented 5 years ago

My file was many thousands of lines long so I tried again starting with 100 lines not changing the above code and it worked! I went to 1000 lines and it broke but gave me a column id

Exception calling "WriteToServer" with "1" argument(s): "Received an invalid column length from the bcp client for colid 3."

so I changed that column from varchar(10) to varchar(128) and those 1000 lines went in and then 2000 lines went in.

I think this is just me not taking the time to start with less data importing.

Thanks closing