Error when using msodbcsql17 to connect to MSSQL database

Questions about Wine on Linux
Locked
0xoak
Newbie
Newbie
Posts: 3
Joined: Tue Aug 27, 2024 9:08 am

Error when using msodbcsql17 to connect to MSSQL database

Post by 0xoak »

Hello,

I am trying to run a Windows application inside Docker that needs to connect to an MSSQL database. I can successfully connect to the database using the same connection string that the app is using via isql, however my app is unable to connect. This is the error that I get:

Code: Select all

winediag:load_odbc failed to open library "/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.6.1": /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.6.1: wrong ELF class: ELFCLASS64
Dockerfile:

Code: Select all

FROM jlesage/baseimage-gui:ubuntu-22.04-v4

ARG WINE_VERSION=stable

ENV WINEARCH=win32
ENV WINEDEBUG=fixme-all+odbc32
ENV WINE_ARGS='App.exe'
ENV LIB_ODBC_DRIVER_MANAGER=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.6.1

ENV WORKDIR=/etc/services.d/app

ENV DEBIAN_FRONTEND=noninteractive

# Install wine and dependencies - https://wiki.winehq.org/Ubuntu
RUN dpkg --add-architecture i386 \
    && apt-get update && apt-get install -y --no-install-recommends \
        curl \
        wget \
        ca-certificates \
        software-properties-common \
        gnupg2 \
        apt-transport-https \
        gpg-agent \
        rename \
        cabextract \
        xvfb \
    && mkdir -pm755 /etc/apt/keyrings \
    && wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key \
    && wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources \
    && apt-get update && apt-get install -y --install-recommends \
        winehq-${WINE_VERSION} \
        wine-${WINE_VERSION} \
        winbind \
    && rm -rf /var/lib/apt/lists/*

# Install winetricks
RUN wget -nv https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks \
    && chmod +x winetricks \
    && mv winetricks /usr/local/bin

RUN winetricks win7
RUN xvfb-run -a winetricks -q dotnet35 vcrun2017

# Install Microsoft ODBC 17
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc \
    && curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | tee /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y \
        msodbcsql17 \
        mssql-tools \
        unixodbc-dev \
    && rm -rf /var/lib/apt/lists/* \
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
    && export PATH="$PATH:/opt/mssql-tools/bin"

WORKDIR ${WORKDIR}

RUN chown -R ${USER_ID}:${GROUP_ID} ${WORKDIR}
RUN chown -R ${USER_ID}:${GROUP_ID} /root/.wine

COPY App.exe .
COPY --chmod=655 startapp.sh /startapp.sh
startapp.sh:

Code: Select all

#!/bin/bash
exec wine $WINE_ARGS
Even if I change

Code: Select all

ENV WINEARCH=win32
to

Code: Select all

ENV WINEARCH=win64
in the Dockerfile I still get the same error.

Thank you for any help in advance!
desessarts
Level 4
Level 4
Posts: 198
Joined: Wed Oct 04, 2023 7:57 am

Re: Error when using msodbcsql17 to connect to MSSQL database

Post by desessarts »

Hello

according to

https://stackoverflow.com/questions/216 ... elfclass64

it seems

"It looks like the object file was compiled on a 64-bit toolchain, and you're using a 32-bit toolchain. Have you tried recompiling the object file in 32-bit mode?"
desessarts
Level 4
Level 4
Posts: 198
Joined: Wed Oct 04, 2023 7:57 am

Re: Error when using msodbcsql17 to connect to MSSQL database

Post by desessarts »

post the result from a shell inside the container
of the command

Code: Select all

file /bin/sh
if there is a link to another shell (like dash for example), post the result if

Code: Select all

file /bin/dash
0xoak
Newbie
Newbie
Posts: 3
Joined: Tue Aug 27, 2024 9:08 am

Re: Error when using msodbcsql17 to connect to MSSQL database

Post by 0xoak »

Thank you for the response!

The source is unfortunately not available for neither the application nor msodbcsql17. The application is 32bit and there is only 64bit msodbcsql17 available. However I ended up installing unixodbc:i386 and tdsodbc:i386 and I am able to query the database.
This is the working Dockerfile:

Code: Select all

# https://wiki.winehq.org/Ubuntu
# https://help.interfaceware.com/kb/904
FROM jlesage/baseimage-gui:ubuntu-22.04-v4

ARG WINE_VERSION=stable

ENV WINEARCH=win32
ENV WINEDEBUG=fixme-all+odbc32
ENV LIB_ODBC_DRIVER_MANAGER=/usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
ENV WINE_ARGS='--version'

ENV WORKDIR=/etc/services.d/app

ENV DEBIAN_FRONTEND=noninteractive

# Install wine and dependencies
RUN dpkg --add-architecture i386 \
    && apt-get update && apt-get install -y --no-install-recommends \
        curl \
        wget \
        ca-certificates \
        software-properties-common \
        gnupg2 \
        apt-transport-https \
        gpg-agent \
        rename \
        cabextract \
        xvfb \
        unixodbc:i386 \
        tdsodbc:i386 \
    && mkdir -pm755 /etc/apt/keyrings \
    && wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key \
    && wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources \
    && apt-get update && apt-get install -y --install-recommends \
        winehq-${WINE_VERSION} \
        wine-${WINE_VERSION} \
        winbind \
    && rm -rf /var/lib/apt/lists/*

# Install winetricks
RUN wget -nv https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks \
    && chmod +x winetricks \
    && mv winetricks /usr/local/bin

RUN winetricks win7
RUN xvfb-run -a winetricks -q dotnet35 vcrun2017 

# RUN dpkg-reconfigure wine-${WINE_VERSION}-amd64 wine-${WINE_VERSION} wine-${WINE_VERSION}-i386

RUN chown -R ${USER_ID}:${GROUP_ID} ${WORKDIR}
RUN chown -R ${USER_ID}:${GROUP_ID} /root/.wine

RUN echo "[ODBC Driver 17 for SQL Server]\n\
Driver = ${LIB_ODBC_DRIVER_MANAGER}\n\
Trace = Yes\n\
TraceFile = ${WORKDIR}/odbc.log" > /etc/odbcinst.ini

WORKDIR ${WORKDIR}
Locked