pyODBC and Unicode Problem

Posted by Aviv Giladi on Stack Overflow See other posts from Stack Overflow or by Aviv Giladi
Published on 2010-06-10T15:41:05Z Indexed on 2010/06/10 15:42 UTC
Read the original article Hit count: 381

Filed under:
|
|
|
|

Hey guys,

I'm working with pyODBC communicate with a MS SQL 2005 Express server. The table to which i'm trying to save the data consists of nvarchar columns.

query = u"INSERT INTO tblPersons (name, birthday, gender) VALUES('" query = query + name + u"', '" query = query + birthday + u"', '" query = query + gender + u"')"

cur.execute(query )

The variables name, birthrday and gende are read from an Excel file and they are Unicode strings. When I execute the query and either look at the table with SQL Server Management Studio or execute a query that fetches the data that was just inserted, all the data that was written in a non-English languages turn into question marks. The data that was written in English is preserved and appears in the table in the correct way. I tried adding CHARSET=UTF16 to my connection string, but had no luck with that. I can use UTF-8 which works fine but as a working convention, I need all the data saved in my DB to be UTF16.

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about server