2010-08-18

[troubleshoot] Error connecting to MSSQL 2005 using python-pymssql

Pernah ketemu error seperti ini  "Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier" saat connect ke  MS SQL 2005 menggunakan Python-PyMSSQL?

Ini solusinya ... semua string mesti di cast ke  nvarchar didalam querynya...
ini kutipannya
http://pymssql.sourceforge.net/faq.php
( "It means that SQL Server is unable to send Unicode data to pymssql, because of shortcomings of DB-Library for C. You have to CAST or CONVERT the data to equivalent NVARCHAR data type, which does not exhibit this behaviour.") 

ini contohnya menggunakan DB dari SAP B1

#!/user/bin/env python

import pymssql
 
conn = pymssql.connect(host='192.168.1.9', user='sa', password='xxxxxx', database='TestDB')
cur = conn.cursor()
cur.execute(' select top 30 docnum, convert(nvarchar, cardcode) , doctotal   \
                from dbo.oinv a   ')
row = cur.fetchall()
print row()

#print row
conn.close()





Powered by ScribeFire.

Tidak ada komentar: