Wrong character encoding from SQL Server to Rails 3 app on Linux via freetds
I'm developing an application on MacOS in Ruby 3.0 using SQL Server 2008 R2 as the database. I'm connecting through freetds and tiny_tds.
When I save a data through a scaffold using extended characters, like ÞþÆæÓó it works fine, the letters are correct when looking at the data in SQL Server Management Studio and when I read the data back into the Rails UI it displays correct.
When I deploy the application on a Linux machine which is also using the freetds and tiny_tds to connect to the same database I get the characters garbled in the UI. When I save the data via the Linux server the characters are displaying correctly in the browser but when looking at the data in SSMS the characters have been encoded and are unreadable (I enter ÞÞðð) and get this in SSMS:
ÞÞðð
This I get in the browser from the Linux server for Suðurnes written into the db from the Mac:
Su�urnes
I have set this line in the database.yml:
encoding: utf8
It didn't change anything. I also set this line in the freetds.conf file:
client charset = UTF-8
The SQL database has Icelandic_CI_AS as the CODEPAGE but I'm pretty sure that is not the fault because it is working correctly from the Mac machine.
I have tested this both on Passenger apache and WEBrick so I don't think it is the apache that is causing this.
So is there any setting on the Linux I have to change to let it behave in similar way as the mac?
Basicly there is something along the way between the web server and the database which is converting the values 开发者_Go百科back and forth.
EDIT: *When I use the tsql command line tool to query the db I get the correct encoding of texts. So as I understand this this is the path: Web Client > Apache > Rails app > Tiny_tds > Freetds > SQL Server So the problem must be on the Apache site or in the rails app itself. It doesn't matter actually if I use Apache or WebBrick so I'm confused on what the issue is. Any ideas?*
Regards, Johann
The problem was that the file freetds.conf had encoding specified which was causing the issue. I also had to make sure that the file database.yml had no encoding specified.
精彩评论