开发者

Pymssql, How to use it to read unicode data from MSSQL2008

I've 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 with mssql from ubuntu using pymssql and freetds. But I can't get unicode data from mssql database. Database collation 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')
  开发者_JAVA技巧 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 is: "Өмнөговь аймаг" Actual result is: "ªìíºãîâü àéìàã"

When I use 'UTF-8' charset, the fetchall() call throws an error means the utf8 can't read the data which is out of range of code page.

How to get unicode data as it stored on mssql database? Please give your hand!

Regards, Orgil


Is it really Unicode data? I.e., is the cc_Name column varchar or nvarchar? It sounds like it's varchar--in which case, try using cp1251 or windows-1251 as the charset instead of iso-8859-1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜