Docker Image SQL Server ODBC Driver - "Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.2' : file not found"

Corey Sheerer 6 Reputation points
2022-01-20T14:17:34.137+00:00

I am having an issue getting sql server odbc driver to work in a docker image. The details are below:

OS Info


NAME="Rocky Linux"
VERSION="8.4 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel fedora"
VERSION_ID="8.4"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.4 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8.4:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"

i have added the odbc trace option in the odbinst.ini file. The full error:

ODBC Trace


[ODBC][31][1642685080.665980][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 0x561eac6f9b80
[ODBC][31][1642685080.666012][SQLAllocHandle.c][377]
Entry:
Handle Type = 2
Input Handle = 0x561eac6f9b80
UNICODE Using encoding ASCII 'ANSI_X3.4-1968' and UNICODE 'UCS-2LE'

[ODBC][31][1642685080.666215][SQLAllocHandle.c][513]
Exit:[SQL_SUCCESS]
Output Handle = 0x561eac700050
[ODBC][31][1642685080.666236][SQLDriverConnect.c][748]
Entry:
Connection = 0x561eac700050
Window Hdl = (nil)
Str In = [DRIVER={ODBC Driver 17 for SQL Server};server=TSVMAEPHQDB019;UID=SubSitesDataRead;PWD=**********][length = 96 (SQL _NTS)]
Str Out = 0x7ffded5a5620
Str Out Max = 2048
Str Out Ptr = (nil)
Completion = 0
[ODBC][31][1642685080.669342][SQLConnect.c][1140]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.2' : file not found
[ODBC][31][1642685080.669379][SQLError.c][424]
Entry:
Connection = 0x561eac700050
SQLState = 0x7ffded5a9c36
Native = 0x7ffded5a9c30
Message Text = 0x7ffded5a9c40
Buffer Length = 500
Text Len Ptr = 0x7ffded5a9c2e
[ODBC][31][1642685080.669414][SQLError.c][474]
Exit:[SQL_SUCCESS]
SQLState = 01000
Native = 0x7ffded5a9c30 -> 0 (32 bits)
Message Text = [[unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.2' : file not found]
[01000][unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.2' : file not found
[ODBC][31][1642685080.669438][SQLError.c][424]
Entry:
Connection = 0x561eac700050
SQLState = 0x7ffded5a9c36
Native = 0x7ffded5a9c30
Message Text = 0x7ffded5a9c40
Buffer Length = 500
Text Len Ptr = 0x7ffded5a9c2e
[ODBC][31][1642685080.669461][SQLError.c][474]
Exit:[SQL_NO_DATA]
[ODBC][31][1642685080.669476][SQLError.c][424]
Entry:
Environment = 0x561eac6f9b80
SQLState = 0x7ffded5a9c36
Native = 0x7ffded5a9c30
Message Text = 0x7ffded5a9c40
Buffer Length = 500
Text Len Ptr = 0x7ffded5a9c2e
[ODBC][31][1642685080.669501][SQLError.c][474]
Exit:[SQL_NO_DATA]
[ISQL]ERROR: Could not SQLDriverConnect
[ODBC][31][1642685080.669524][SQLFreeHandle.c][290]
Entry:
Handle Type = 2
Input Handle = 0x561eac700050
[ODBC][31][1642685080.669553][SQLFreeHandle.c][339]
Exit:[SQL_SUCCESS]
[ODBC][31][1642685080.669569][SQLFreeHandle.c][220]
Entry:
Handle Type = 1
Input Handle = 0x561eac6f9b80

Some important notes:

1) i have followed microsofts exact instructions, uninstalling unixODBC before installing: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#debian17
2) i ran chmod 777 -R to verify there was no permissions issues on the driver / path
3) verified the path to the driver is correct and the driver's name is correct.

odbcinst.ini file below:


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

[ODBC]
Trace=Yes
TraceFile=/dev/stdout

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,347 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Corey Sheerer 6 Reputation points
    2022-01-20T20:55:42.99+00:00

    Not a great solution, but i was able to move to debian bullseye-slim and install the odbc driver. I did get a cannot connect error which was fixed by updateing the opennssl.conf. Apparently, TLS 1.2 is not supported for the odbc driver:

    sed -i 's/TLSv1.2/TLSv1/g' /etc/ssl/openssl.cnf \
    sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf

    The connection works after this.


  2. Brian Lauber 1 Reputation point
    2022-02-02T20:12:01.51+00:00

    To summarize the other thread: mssql-tools appears to have an unstated dependency on libgssapi-krb5-2 . The quick fix is to just install libgssapi-krb5-2 manually:

    sudo apt-get install libgssapi-krb5-2
    

    You can verify this issue by comparing the outputs of the ldd and apt show commands. First, notice that the ldd command mentions that one of the dynamic libraries that it needs is missing:

    > ldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.8.so.1.1 | grep found
    
        libgssapi_krb5.so.2 => not found
    

    However, this dependency is not mentioned in the mssql-tools package:

    > apt show mssql-tools
    
    
    Package: mssql-tools
    Version: 17.8.1.1-1
    Section: database
    Maintainer: Microsoft SQL Tools Team <mssql-tools@microsoft.com>
    Installed-Size: unknown
    Depends: libc6 (>= 2.19), libstdc++6 (>= 4.8.2), libkrb5-3, openssl, debconf (>= 0.5), msodbcsql17 (>= 17.3.0.0)
    Download-Size: 211 kB
    APT-Manual-Installed: yes
    APT-Sources: https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
    Description: Tools for Microsoft(R) SQL Server(R)
     This package provides tools for Microsoft(R) SQL Server(R).
    
    N: There are 2 additional records. Please use the '-a' switch to see them.
    
    0 comments No comments