Pyodbc 连接错误

Posted

技术标签:

【中文标题】Pyodbc 连接错误【英文标题】:Pyodbc Connection Error 【发布时间】:2015-04-01 14:59:02 【问题描述】:

代码

这是我在 linux Red Hat 64bit 中使用 python 2.6 输入的代码

import pyodbc

print pyodbc.dataSources()

print "Connecting via ODBC"

conn = pyodbc.connect("DRIVER=NetezzaSQL;SERVER=localhost;PORT=5480;DATABASE=Database;UID=santiago;PWD=ha123;")

错误

这是我在运行 pyodbc 时收到的真正错误。我不知道这种语言是什么或它是什么意思?

'ODBC': '', 'NetezzaSQL': '/usr/local/nz_7.2.0.3/lib64/libnzodbc.so'
Connecting via ODBC
Traceback (most recent call last):
  File "connect.py", line 41, in <module>
conn = pyodbc.connect("DRIVERNetezzaSQL;SERVER=localhost;PORT=5480;DATABASE=Database;UID=santiago;PWD=ha123;")
pyodbc.Error: ('H00', '[H00] [unixODBC]Sre n/rpr trbtsaeepy\xc8 (33) (SQLDriverConnectW)')

obdcinst.ini

这是使用的obdcinst文件

[ODBC Drivers]
NetezzaSQL = Installed

[NetezzaSQL]
Driver           = /usr/local/nz_7.2.0.3/lib64/libnzodbc.so
Setup            = /usr/local/nz_7.2.0.3/lib64/libnzodbc.so
APILevel         = 1
ConnectFunctions = YYN
Description      = Netezza ODBC driver
DriverODBCVer    = 03.51
DebugLogging     = false
LogPath          = /tmp
UnicodeTranslationOption = utf8
CharacterTranslationOption = all
PreFetch         = 256
Socket           = 16384

obdc.ini

这是使用的odbc配置文件

;
;  odbc.ini
;
[ODBC Data Sources]
NZSQL = NetezzaSQL


[NetezzaSQL]
;Path of a driver used for database connection
Driver                = /usr/local/nz_7.2.0.3/lib64/libnzodbc.so

;A decription used to identify the database connection properties.
Description           = NetezzaSQL ODBC

;The name of a machine or IP address where the database is located.
Servername            = 127.0.0.1

;The port number to connect.
Port                  = 5480

;The name of a database.
Database              = dev

;The name of a valid user.
Username              = guest

;The password for  the user.
Password              = password

;Only Select SQL statements will be allowed if this field is checked.
ReadOnly              = false

;When this option is enabled and the application bindtype is same as   backend
;datatype the query performance will be faster.Query performance gain will be achieved 
;only for single select statements (not for batch queries).It also works in case when
;application bind type is different than backend datatype but there are some restrictions on it.
FastSelect            = false

;When set to true, system tables will be included in the available table list.
ShowSystemTables      = false

;When set to true, use old (2.5) functionality for returning schemas in  SQLTables.
LegacySQLTables       = false

;Specifies login timeout in seconds.
LoginTimeout          = 0

;Specifies query timeout in seconds.
QueryTimeout          = 0

;Specifies date format as follows -
; 1: YMD
; 2: MDY
; 3: DMY
DateFormat            = 1

;When selected, driver treats SQL_C_NUMERIC buffers as SQL_C_CHAR   buffers.
NumericAsChar         = false

;Return SQL_BIT as "1"/"0" when char.
SQLBitOneZero         = false

;When enabled, replaces all occurences of CRLF, CR and LF with a single space.
StripCRLF             = false

;Specifies level of security on the system
securityLevel         = preferredUnSecured

;Name of the Root CA certificate.
caCertFile            =

;Specifies maximum errors allowed. 0 value means no limit on  loadMaxErrors value.
;loadMaxErrors         = 1

;If value is true, it rounds the data of numeric columns whose precision  exceeds the precision defined.
;loadRoundFraction     = 0


[ODBC]
IANAAppCodePage=4
InstallDir=/opt/odbc32v51
Trace=0
TraceDll=/opt/odbc32v51/lib/odbctrac.so
TraceFile=odbctrace.out
UseCursorLib=0

如果需要其他任何东西来确定解决方案,请告诉我。

【问题讨论】:

【参考方案1】:

我无法告诉您错误的含义,因为我也无法识别该语言。但是,Netezza ODBC 端口是 5480,而您在连接方法中指定 5668。另外,您真正要连接的数据库实际上是否名为“数据库”?

【讨论】:

我更改了属性,因为将私人信息放在网络上不好,但我得到了正确的数据库,并且原始代码中包含了 5480。我使用具有原始属性的 python 在 Windows 中运行相同的代码并且它可以工作,但在我的 linux 机器上它不工作。 您可能希望始终一致地更改它,否则它看起来像配置/参数错误(请参阅您稍后在示例 ODBC.ini 中指定的端口) 谢谢,我编辑了这个问题。你认为这可能是 python 解释器的问题吗?

以上是关于Pyodbc 连接错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 pyodbc 导致错误:未找到数据源名称且未指定默认驱动程序

使用 PyInstaller 编译得到 pyodbc 后如何在启动时修复错误?

Informix、pyodbc、Centos

与 Hive 的 Python 连接

Access数据库连接错误

在 64 位 PC 上找不到数据源名称的 pyodbc 错误或没有默认驱动程序