pyodbc & FreeTDS: Can I work with NVARCHAR column on MSSQL2008

43 views
Skip to first unread message

Orgil

unread,
Jan 31, 2011, 7:42:21 AM1/31/11
to pyodbc
Hello.
I have FreeTDS, pyodbc-2.1.8, python-2.6, ubuntu-10.4.
I also have MSSQL2008 database server on Windows7.

My question is: Can I get unicode data from nvarchar column on
Mssql2008 database using pyodbc?
To do this, what does other library or configuration need me?

I use FreeTDS driver to connect with mssql by pyodbc. But I don't know
version of FreeTDS.
How to know the version of FreeTDS?

My current state is, I can connect with mssql. But I can not get
unicode data!
My code is:
-----------------------
import pyodbc
conn =
pyodbc.connect(r'DRIVER={FreeTDS};SERVER=10.0.0.61\mssql2008;DATABASE=eoffice_clone;UID=erp;PWD=123;CHARSET=UCS-2;')
crms = conn.cursor()
crms.execute("SELECT cc_Name FROM tblHR_CodeClass")
for line in crms:
print 'cc_Name:', str(line.cc_Name)
conn.close()
-----------------------
Expected result is 'cc_Name: Аймаг, хот', but instead
'cc_Name: ?????, ???' comes.

Please, share your experience!

regards,
Orgil

daniel....@zumtobel.com

unread,
Jan 16, 2013, 8:44:45 AM1/16/13
to pyo...@googlegroups.com
hi any news on this? i've ran into the same problem

mtp.br...@gmail.com

unread,
Jan 20, 2013, 10:52:20 PM1/20/13
to pyo...@googlegroups.com
Check if you are specifying a client charset in freetds.conf

Assuming you are using TDS7+, FreeTDS will translate the UCS-2 data it receives into something more universal. It is potentially defaulting to ASCII instead of UTF-8. Read the following and see if it helps:
It looks like the author was inserting data instead of selecting so I can't confirm that it's the same issue since he gets a data conversion error.

Also, you can check what version of FreeTDS you have by doing "tsql -C".
Reply all
Reply to author
Forward
0 new messages