French characters into SQL Server

  • Hi all,

    I use Powershell to deploy DB scripts. In one script file, I have French accented characters.

    When I call Invoke-sqlcmd and pass the script to the -inputfile, the French characters get mangled.

    In the bad old days, the workaround was to save the files as unicode, and sqlcmd would handle them OK.

    How do I go about this in this brave new world?

    Thanks!

    Paul

  • Cmdlet Out-File has a -Encoding option.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Forgive me, maybe it's too early on Monday, but I'm not sure how that helps me?

    The source file is fine, it's getting the accents into SQL Server that's problematic.

  • Sorry I misunderstood the scenario. Try changing the input file encoding from UTF-16LE (what Microsoft calls "Unicode") to UTF-32 and see if passing that file works. It's a workaround but I think you need it for Invoke-SqlCmd to get the job done. It's an open issue with the file handling in the Cmdlet.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • I was able to Set-Content of the source files to Unicode, and they appeared OK when opened in SSMS.

    I had a test version working fine; but when those files were passed to Invoke-Sqlcmd, the accented chars were again mangled.

    So I've reverted to using sqlcmd.

    Thanks for taking the time to respond.

    P

  • You're welcome. Happy you got it sorted.

    As I said though, "Unicode" = UTF-16LE. I was saying to try the input file in UTF-32 format. Something like this would have created it:

    "Hello world!" | Out-File -FilePath C:\InputFile.txt -Encoding UTF32

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Using Powershell 3, I had the same problem but ended up doing this:

    $UnicodeFileName = $ScriptPath + "\UnicodeFileContent.sql"

    $FileContent = Get-Content $FileName

    $FileContent | Out-File -FilePath $UnicodeFileName -Encoding Unicode

    Invoke-Sqlcmd -ServerInstance $SqlServer -Database $Database -InputFile $UnicodeFileName -AbortOnError -Verbose

    ___________________________________
    I love you but you're standing on my foot.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply