mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 562 forks source link

PyODBC to SQL connectivity issue on RHEL8 server #1158

Closed AASupport123 closed 1 year ago

AASupport123 commented 1 year ago

Please first make sure you have looked at:

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

Issue

Often it is easiest to describe your issue as "expected behavior" and "observed behavior". PyODBC to SQL Server connection is getting failed with the error message 'file not found (0) (SQL Driver Connect)' on RHEL8 server. We have tried using SQL Server 13.1, 17.2, 17.4, 18.0 and 18.1 versions connectivity from python 3.7/3.9 versions using PyODBC on RHEL8 server. Please find the below error message we received when trying the connectivity in python for any version of sql server.

Connection Code: import pyodbc conn = pyodbc.connect('Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1;' 'Server=xx,xxxxx;' 'Database=xx;' 'UID=xx;' 'PWD=xxx;' 'Encrypt=False;' 'TrustServerCertificate=yes') cursor = conn.cursor()

Error Message: Connecting to MS SQL driver 17.2 version from python : pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1' : file not found (0) (SQLDriverConnect)")

Connecting to MS SQL driver 18.0 version from python : pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1' : file not found (0) (SQLDriverConnect)")

gordthompson commented 1 year ago

First, verify that the file actually exists

$ ls -la /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17*
-rwxr-xr-x 1 root root 2059792 Nov 17 15:01 /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.2.1

Then, run ldd on that file to see if there are any dependencies that ldd cannot resolve

$ ldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.2.1 
    linux-vdso.so.1 (0x00007fff1f54f000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f561e81f000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f561e617000)
    libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f561e3fc000)
    libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f561e126000)
    libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f561dedb000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f561db52000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f561d7b4000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f561d59c000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f561d37d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f561cf8c000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f561ee2e000)
    libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f561cd5a000)
    libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f561cb56000)
    libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f561c94b000)
    libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f561c747000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f561c52d000)

If one of those dependencies was missing it would appear as

    libkrb5.so.3 => not found
v-chojas commented 1 year ago

Did you double-post? https://github.com/mkleehammer/pyodbc/discussions/1157