简体   繁体   English

使用ODBC无法读取的数据库错误

[英]Unreadable database error using ODBC

I'm using pypyodbc and FreeTDS to connect to SQL Server 2008. I occasionally get errors but I can't ever read the error message. 我正在使用pypyodbc和FreeTDS连接到SQL Server2008。我偶尔会遇到错误,但是我永远无法读取错误消息。 I've tried decoding the string from UTF-8 and it is still illegible. 我尝试从UTF-8解码字符串,但仍然难以辨认。 Does anyone know how I can get human readable error messages? 有谁知道我如何获得人类可读的错误消息?

This is my connection string: 这是我的连接字符串:

conn = pypyodbc.connect('DRIVER=FreeTDS;SERVER=myserver;PORT=1433;DATABASE=mydb;UID=myuid;PWD=mypw;CHARSET=UTF-8;TDS_Version=8.0;', unicode_results=True)

This is the error message: 这是错误消息:

pypyodbc.DatabaseError: (u'\u3130\u30300', u'[\u3130\u30300] \u755b\u696e\u4f78\u4244\u5d43\u445b\u6972\u6576\u2072\u614d\u616e\u6567\u5d72\u6143\u276e\u2074\u706f\u6e65\u6c20\u6269\u2720\u752f\u7273\u6c2f\u6269\u782f\u3638\u365f\u2d34\u696c\u756e\u2d78\u6e67\u2f75\u646f\u6362\u6c2f\u6269\u6474\u6f73\u6264\u2e63\u6f73\u2027\u203a\u6966\u656c\u6e20\u746f\u6620\u756f\u646e')

It turns out that the error string is stored in the unicode object as UTF-16. 事实证明,错误字符串以UTF-16的形式存储在unicode对象中。 Calling encode('utf-16LE') on the error string gave me a readable string back. 在错误字符串上调用encode('utf-16LE')给了我一个可读的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM