GraveyardWorker21005
GraveyardWorker21005

Reputation: 15

Strange character when importing '.csv' file in SSIS

So I'm trying to use SSIS to import a '.csv' file into SQL Server. The import works fine but the issue I'm having is that when I import the file, each field has the character � appended.

I've been trying all morning to fix this through SSIS but I'm not having any luck. What I have just noticed is that when I open the '.csv' file and go to Save As it shows up as Unicode Text rather than an actual csv. If I save it as a csv and then run that through all the fields come through fine without the � character.

So I have a fix of sorts but it requires me manually opening and re-saving the files, which I can't have as I need the process to be able to run automatically. I had the thought of converting the file automatically using a C# script task but I don't know how to do that, is anybody able to assist? Or is there a better way to do it that I don't know of?

Thank you.

Upvotes: 1

Views: 987

Answers (1)

Dávid Molnár
Dávid Molnár

Reputation: 11533

You can use a simple Powershell script to change the encoding:

foreach ($file in Get-ChildItem *.csv) {
    Get-Content $file.name | Set-Content -Encoding utf8 "UTF8_$($file.name)"
}

Upvotes: 1

Related Questions