2012-02-29 51 views
0

我在我的windows 2k3 x64上使用pymssql 1.9.908出現問題。 我用下面的代碼來測試一個簡單的查詢。但是我收到此錯誤:pymssql查詢時出錯1.9.908

Traceback (most recent call last): 
    File "<pyshell#5>", line 1, in <module> 
    cur.execute('SELECT * from tbl_staticDetails') 
    File "pymssql.pyx", line 296, in pymssql.Cursor.execute (pymssql.c:3246) 
OperationalError: SQL Server message 4004, severity 16, state 1, line 1: 
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. 
DB-Lib error message 4004, severity 16: 
General SQL Server error: Check messages from the SQL Server 

下面是IDLE輸入我的示例代碼:

>>> import pymssql 
>>> conn = pymssql.connect(host='<IP reachable by my machine>', user='sa', password='<password>', database='<database nbame>') 
>>> cur = conn.cursor() 
>>> cur.execute('SELECT * from tbl_staticDetails') 

任何想法是極大的讚賞。 非常感謝!

回答

0

參考http://pymssql.sourceforge.net/faq.php

In SQL 2000 SP4 or newer, SQL 2005 or SQL 2008, if you do a query that returns NTEXT type data, you may encounter the following exception: _mssql.MssqlDatabaseError: SQL Server message 4004, severity 16, state 1, line 1: 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.

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.

+0

所以我只是使字段的數據類型在我的表CHAR和它是否行得通呢?謝謝 – jaysonpryde 2012-02-29 15:09:17