pyodbc连接SQL Server出现中文乱码问题的解决方案
2013-05-17 16:44
881 查看
添加一个配置参数unicode_results=True
connect(*connectionstring, **kwargs)
--> Connection
Creates and returns a new connection to the database.
The optional connection string can be passed as a string or Unicode object (connectionstring), as keywords (kwargs),
or both.
The DB API recommends some keywords that are not usually used in ODBC connection strings, so they are converted:
Some keywords are used by pyodbc and are not passed to the odbc driver:
The ansi keyword should only be used to work around driver bugs. pyodbc will determine if the Unicode connection function (SQLDriverConnectW) exists and always attempt to call it. If the driver returns IM001 indicating it does not support the Unicode version,
the ANSI version is tried (SQLDriverConnectA). Any other SQLSTATE is turned into an exception. Setting ansi to true skips the Unicode attempt and only connects using the ANSI version. This is useful for drivers that return the wrong SQLSTATE (or if pyodbc
is out of date and should support other SQLSTATEs).
For help on connection strings, see ConnectionStrings
pyodbc.connect(connStr,unicode_results=True)
资料(摘自http://code.google.com/p/pyodbc/wiki/Module):
connect
connect(*connectionstring, **kwargs)--> Connection
Creates and returns a new connection to the database.
The optional connection string can be passed as a string or Unicode object (connectionstring), as keywords (kwargs),
or both.
# a string cnxn = connect('driver={SQL Server};server=localhost;database=test;uid=me;pwd=me2')
# keywords cnxn = connect(driver='{SQL Server}', server='localhost', database='test', uid='me', pwd='me2')
# both cnxn = connect('driver={SQL Server};server=localhost;database=test', uid='me', pwd='me2')
The DB API recommends some keywords that are not usually used in ODBC connection strings, so they are converted:
from | converted to |
host | server |
user | uid |
password | pwd |
keyword | description | default |
autocommit | If False, Connection.commit must be called; otherwise each statement is automatically commited | False |
ansi | If True, the driver does not support Unicode and SQLDriverConnectA should be used | False |
unicode_results | If True, strings returned in result sets are always Unicode (2.1.5+) | False |
readonly | If True, the connection is set to readonly | False |
the ANSI version is tried (SQLDriverConnectA). Any other SQLSTATE is turned into an exception. Setting ansi to true skips the Unicode attempt and only connects using the ANSI version. This is useful for drivers that return the wrong SQLSTATE (or if pyodbc
is out of date and should support other SQLSTATEs).
For help on connection strings, see ConnectionStrings
相关文章推荐
- asp.net插入sql server 中文乱码问题解决方案
- 解决securecrt连接linux,出现的中文乱码问题
- mysql中文出现乱码问题的彻底解决方案
- javaweb项目出现中文乱码问题的解决方案。
- 同样遇到PHP 连接SQL2008 查询出现中文乱码问题
- jquery+jsp+servlet做$.ajax交互时出现中文乱码(字符集问题)的解决方案
- SQL Server插入中文数据出现乱码问题
- 在SQL Server 2005(2008)中用T-SQL插入中文数据时出现的问号或乱码的解决方案
- pthhon连接数据库的中文乱码问题解决方案
- PHP 中 DOMDocument保存xml时中文出现乱码问题的解决方案
- PHP返回mysql数据库中文字符出现乱码问题之解决方案
- 关于 Hibernate3 与 Mysql5.5 连接时出现的中文乱码问题
- sakai修改sakai.properties的字段为中文运行后出现乱码的问题分析与解决方案!
- 关于response.sendRedirect传递中文出现乱码问题的解决方案
- Mac 下 MySQL 5.7 连接 navicat 中文乱码问题终极解决方案
- JSP中乱码问题解决(一、JSP页面显示乱码,二、表单提交中文时出现乱码,三、数据库连接出现乱码,四、数据库的显示乱码 )
- domino连接mysql插入中文内容出现乱码的解决方案
- [原创]关于cvs客户端(ECLIPSE内置)连接CVS服务器中文乱码问题解决方案
- Informix数据库通过ODBC驱动连接中文乱码问题解决方案
- linux 连接mysql中文出现乱码的问题