pyodbc SQL Server Driver Error [unixODBC][Driver Manager] Can't open lib '/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.1.1’

uyhoqukh  于 2023-10-15  发布在  SQL Server
关注(0)|答案(1)|浏览(154)

I have been unable to connect to SQL Server using pyodbc

pyodbc.connect(f'DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={host};DATABASE={db};UID={user};PWD={pwd};TrustServerCertificate=yes;')

Getting an error: Can't open lib '/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.1.1’

I am however able to run this command and it connects fine:

isql -v -k “DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={host};DATABASE={db};UID={user};PWD={pwd};TrustServerCertificate=yes;”

I have tried every suggestion. Even added the sql server driver path to my LD_LIBRARY environment variable.

Here is what I get after running: odbcinst -q -d

[ODBC Driver 18 for SQL Server]
[ODBC Driver 17 for SQL Server]

odbcinst -j

$ odbcinst -j unixODBC 2.3.7
DRIVERS. . . .......: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES /etc/ODBCDataSources
SQLULEN Size........:8
SQLLEN Size.........:8
SQLSETPOSIROW Size.: 8

This is the content of odbcinst.ini

[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.1.1
UsageCount=1

[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1
UsageCount=1

Running RHEL 8, python 3.9.10 and pyodbc==4.0.39

More details

import pyodbc

pyodbc.drivers()
# ['ODBC Driver 18 for SQL Server', 'ODBC Driver 17 for SQL Server']

pyodbc.dataSources()
#{}
n53p2ov0

n53p2ov01#

Looking at the comments on the OP question, in which it's mentioned that the python module is loaded and not necessarily installed on your system, this could be related to version of the gcc that was used to compile the python binaries not being compatible with the version used to compile the unixODBC binaries. I had a similar issue once.

  • So I ended up installing python directly on the system. That resolved the issue for me.
  • If that is not possible, try to load a different version of python from the module repository. That version of python might have been compiled with a different version of the gcc.

相关问题