4

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')
   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

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
Orgil
  • 187
  • 3
  • 13

1 Answers1

2

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.

Dave Huang
  • 746
  • 1
  • 5
  • 13
  • Thanks for your answer. cc_Name is NVARCHAR column. – Orgil Feb 27 '11 at 02:56
  • A very old answer, but still useful in 2016! This was boggling me for awhile, as my charset was not unicode, but I couldn't get the translation correct from my pymssql query. Thanks. – Neal Magee Aug 31 '16 at 20:08