|We don't bite newbies here... much|
DBI, unicode, ms sql serverby zod (Scribe)
|on Feb 08, 2009 at 02:01 UTC||Need Help??|
zod has asked for the
wisdom of the Perl Monks concerning the following question:
When inserting unicode text (chinese in my case) into MySQL, I set up the connection like so:
However, I haven't been able to replicate this on MS SQL Server 2008.
My connection looks like this:
That allows me to connect and select from tables, etc., but when I try to insert Chinese text, it inserts garbage. So, how do you specify utf-8 for the ODBC driver? Any ideas?
UPDATE: I resolved this. I'll spare you the gory details involved with my particular environment (chinese version of windows on one box, not another, collations, etc.), but the key turns out to be this from the SQL Server BOL:
"When referencing the Unicode character data types nchar, nvarchar, and ntext, 'expression' should be prefixed with the capital letter 'N'. If 'N' is not specified, SQL Server converts the string to the code page that corresponds to the default collation of the database or column. Any characters not found in this code page are lost."
I did not have the "N" on my insert statement in perl. So, this worked with the 'N':