Pymssql how to use it to read Unicode data from MSSQL2008

I used pymssql-1.0.2 and freetds-0.82.7 on ubuntu-10.10. Also, I have a mssql2008 server on Windows 7. I can connect to mssql from ubuntu using pymssql and freetds. But I cannot get Unicode data from the mssql database. Database mapping is Cyrillic_General_CI_AS.

My freetds.conf file looks like this:

[mssql2008] host=10.0.0.34 port=1433 tds version=7.0 

My code looks like this:

  conn = pymssql.connect(host=10.0.0.34\mssql2008, user=***, password=***, database=eoffice, as_dict=true, charset='iso-8859-1') crms = conn.cursor() crms.execute('SELECT cc_Name FROM tblHR_CodeClass') for row in crms.fetchall(): raise u"Succeeded! Test data: " + row['cc_Name'] break 

Expected Result: “Өө é" "” Actual Result: “ªіөã ééà" ""é" "" "éìì "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""é" "" "" "" éé "é "é "é "é "é "é ""é"

When I use UTF-8 encoding, calling fetchall () throws an error, since utf8 cannot read data that is outside the range of the code page.

How to get unicode data stored in mssql database? Please give your hand!

Regards, Orgil

+4
source share
1 answer

Is this really Unicode data? Ie, is a cc_Name varchar or nvarchar column? This seems to be varchar - in this case, try using cp1251 or windows-1251 as the encoding instead of iso-8859-1.

+1
source

Source: https://habr.com/ru/post/1341069/


All Articles