pyodbc:unixODBC 驱动程序错误 SQL_HANDLE_HENV 上的 SQLAllocHandle 失败

问题描述 投票:0回答:1

我正在尝试使用带有以下代码片段的 DSN 从

pyodbc
查询 SQL Server:

import pyodbc

pyodbc.autocommit = True

conn = pyodbc.connect('DSN=SQLSERVER_CONN')
cursor = conn.cursor()
cursor.execute('select count(1) from jupiter.fact_load')
result = cursor.fetchall()

for row in result:
   print(row)

cursor.close()
conn.close()

我的 .odbc.ini 看起来:

[SQLSERVER_CONN]
Description=Connection to SQLSERVER UAT
DRIVER=/home/aiman/mssql-jdbc/9.2.0/libmsodbcsql-11.0.so.2270.0
SERVER=my.sqlserver.com,10501
DATABASE=jupiter
UID=aiman
PWD=xxxxx
Trusted_Connection=yes

它给了我以下错误:

Traceback (most recent call last):
  File "test_odbc.py", line 5, in <module>
    conn = pyodbc.connect('DSN=SQLSERVER_CONN')
pyodbc.Error: ('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)")

在一篇文章中,我读到当 .rll 文件不存在时会发生这种情况,但驱动程序路径中存在两个文件(驱动程序和 .rll):

libmsodbcsql-11.0.so.2270.0
msodbcsqlr11.rll

类似的问题被给出了here

echo "default:x:$uid:0:user for openshift:/tmp:/bin/bash" >> /etc/passwd
),但我不能这样做,因为它会覆盖系统帐户设置,并且我正在尝试从我自己的ID运行。

python sql-server odbc pyodbc
1个回答
0
投票

正如@AlwaysLearning 所强调的,这是不兼容的驱动程序问题。
获得兼容的驱动程序:lib64/libmsodbcsql-17.2.so.0.1.
现在工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.