pymssql 读取nvarchar ntext 报错

  Python 开发一个程序,用pymssql读取sql server 2005 数据库,在使用中出现下面错误

  File "C:"Python25"Lib"site-packages"pymssql.py", line 188, in execute
    raise OperationalError, e[0]
OperationalError: SQL Server message 4004, severity 16, state 1, line 1:

不能用 DB-Library (如 ISQL)或 ODBC 3.7 或更早版本将 ntext 数据或仅使用 Unicode 排序规则的 Unicode 数据发送到客户端。

  找了一下资料, sql server中 ntext 和 nvarchar 采用unicode编码存储内容的, pymssql 读取这种类型字段的时候会报错。

  guid(nvarchar) content(ntext)

  select guid,content from news

  就会报上面的错误

解决方法

(1) 在语句中转换一下数据类型 select convert(varchar(50),guid) as guid, convert(text,content) as content from news

(2) 数据库设计避免使用 nvarchar ntext

 

 


posted @ 2009-03-12 10:39  mapig  阅读(808)  评论(0编辑  收藏  举报