Can t open lib odbc driver 17 for sql server

Cant open lib ODBC Driver 17 for SQL Server : file not found

Questions : Cant open lib ODBC Driver 17 for SQL Server : file not found

2022-09-26T22:42:36+00:00 2022-09-26T22:42:36+00:00

8851

I am fairly new to Python and Azure web anycodings_azure apps. Any help is appreciated.

My setup:

  • Program: Visual Studio code
  • Language: Python-Flask
  • Cloud provider: Microsoft Azure
  • Database: Azure SQL DB
  • Deployment option: Docker image > Azure container registry > Deploy the image to the Web app
  • Web App OS: Linux (I think Alpine?)

In my code, I am using pyodbc to connect to anycodings_azure the Azure SQL DB. The code runs anycodings_azure successfully locally in the terminal. anycodings_azure However, when it runs on the web, it anycodings_azure encounters the following error:

Error: ('01000', "[01000] [unixODBC][Driver anycodings_azure Manager]Can't open lib 'ODBC Driver 17 for anycodings_azure SQL Server' : file not found (0) anycodings_azure (SQLDriverConnect)")

I followed several troubleshooting posts, anycodings_azure however, I have not been successful.

I tried using the $sudo ln to create a anycodings_azure symbolic link that resulted in permission anycodings_azure denied. I think this is a known limitation anycodings_azure of the Azure web app.

I tried to look for the driver in anycodings_azure etc/odbcinst.ini to see if the driver name anycodings_azure exists, however, I am pretty new to Azure / anycodings_azure VS Code so I do not even know how to open anycodings_azure the file that is in the, etc/ folder. I do anycodings_azure see it in the BASH command prompt when I anycodings_azure navigate to the etc/ folder but not sure how anycodings_azure to open the file.

I ran the following command in the BASH to anycodings_azure install PYODBC, but that didn't resolve the anycodings_azure issue.

python -m pip install pyodbc

The result from odbcinst -j

unixODBC 2.3.4 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /home/a49d42b0d7b8ce200a4f7e74/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8

My dockerFile:

# Pull a pre-built alpine docker image with nginx and python3 installed FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 ENV LISTEN_PORT=8000 EXPOSE 8000 COPY /app /app # Uncomment to install additional requirements from a requirements.txt file COPY requirements.txt / RUN pip install --no-cache-dir -U pip RUN pip install --no-cache-dir -r /requirements.txt RUN apk add g++ RUN apk add unixodbc-dev RUN pip install pyodbc

My requirements.txt. I commented out anycodings_azure pyodbc; I think that's okay since I am anycodings_azure installing it in the docker file.

click==6.7 Flask==0.12.2 itsdangerous==0.24 Jinja2==2.10 MarkupSafe==1.0 Werkzeug==0.14.1 #pyodbc==4.0.28

Additional questions:

  1. Should I be using PYODBC? or is there something better / more compatible I should be using?
  2. Should I use MYSQL instead of Azure SQL DB?
  3. Is there a way for me to open the odbcinst.ini file that is on the web app?

Total Answers 3

31

Answers 1 : of Cant open lib ODBC Driver 17 for SQL Server : file not found

First, if you want to know what os anycodings_python release is in your docker, you can anycodings_python command cat /etc/os-release to get it, anycodings_python such as run it in my ubuntu as the anycodings_python figure below.

At here, I'm sure your web app os is anycodings_python Alpine Linux, due to the first line of anycodings_python your docker file FROM anycodings_python tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7. anycodings_python Your base image is based on Alpine 3.7.

Second, according to your error info anycodings_python Error: ('01000', "[01000] anycodings_python [unixODBC][Driver Manager]Can't open lib anycodings_python 'ODBC Driver 17 for SQL Server' : file anycodings_python not found (0) (SQLDriverConnect)") and anycodings_python the content of your docker file and anycodings_python requirements.txt, I think the issue was anycodings_python caused by missing MS SQL Server ODBC anycodings_python driver for Linux which not be installed anycodings_python in your docker image, but pyodbc anycodings_python required it to connect Azure SQL anycodings_python Database.

However, for ODBC Driver 17 for SQL anycodings_python Server, the offical document Installing anycodings_python the Microsoft ODBC Driver for SQL Server anycodings_python on Linux and macOS shows there is not a anycodings_python released v17 package for Alpine. So the anycodings_python workaround is to change your DockerHub anycodings_python base image from anycodings_python tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7 anycodings_python to tiangolo/uwsgi-nginx-flask:python3.6 anycodings_python to use debian as OS, then you can easily anycodings_python install MS ODBC driver 17 for SQL Server anycodings_python in it.

For your additional questions, as below.

  1. Except for using pyodbc, pymssql is the anycodings_python other one of Python SQL Driver, please anycodings_python see the offical document Python SQL anycodings_python Driver, but The Pymssql Project is Being anycodings_python Discontinued. And SQLAlchemy as ORM anycodings_python framework can be used to connect Azure anycodings_python SQL Database, which also requires pyodbc anycodings_python or pymssql.

  2. Use MySQL or Azure SQL Database, it's up anycodings_python to you. I think the only difference is anycodings_python that MySQL may be installed easiler than anycodings_python Azure SQL DB in Alpine.

  3. The way to open odbcinst.ini file on anycodings_python webapp is to use vim over SSH to connect anycodings_python to your docker OS. Considering for the anycodings_python custom docker image you used, please see anycodings_python the section Enable SSH of the offical anycodings_python document Configure a custom Linux anycodings_python container for Azure App Service and anycodings_python replace the command apk with apt for anycodings_python Debian Linux.

0

2022-09-26T22:42:36+00:00 2022-09-26T22:42:36+00:00Answer Link

mRahman

1

Answers 2 : of Cant open lib ODBC Driver 17 for SQL Server : file not found

The following instructions in the anycodings_python official website helped me solve my anycodings_python problem: Install the Microsoft ODBC anycodings_python driver for SQL Server (Linux)

curl //packages.microsoft.com/keys/microsoft.asc | apt-key add - #Download appropriate package for the OS version #Choose only ONE of the following, corresponding to your OS version #Debian 8 (only supported up to driver version 17.6) curl //packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list #Debian 9 curl //packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list #Debian 10 curl //packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list exit sudo apt-get update sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17 # optional: for bcp and sqlcmd sudo ACCEPT_EULA=Y apt-get install -y mssql-tools echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc # optional: for unixODBC development headers sudo apt-get install -y unixodbc-dev # optional: kerberos library for debian-slim distributions sudo apt-get install -y libgssapi-krb5-2

0

2022-09-26T22:42:36+00:00 2022-09-26T22:42:36+00:00Answer Link

joy

6

Answers 3 : of Cant open lib ODBC Driver 17 for SQL Server : file not found

The official website instructions did anycodings_python not work for me as the packages were anycodings_python reported as missing:

$ sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package msodbcsql18

The following worked for me:

sudo apt-get install unixodbc

Navigate with a browser too:

//packages.microsoft.com/ubuntu/21.04/prod/pool/main/m/

Download the deb files in:

  • msodbcsql18
  • mssql-tools18
    Or
  • msodbcsql
  • msodbcsql17

Pick the version you want to install. I anycodings_python picked 18.

Install the two deb files:

sudo dpkg -i mssql-tools18_18.0.1.1-1_amd64.deb sudo dpkg -i msodbcsql18_18.0.1.1-1_amd64.deb

If you had not run the script on the anycodings_python official website then you need to run anycodings_python the following (for 18 rather than 17):

echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc

0

2022-09-26T22:42:36+00:00 2022-09-26T22:42:36+00:00Answer Link

raja

How do I install ODBC driver 17 for SQL Server in Python?

Windows.
Download Python installer. If your machine doesn't have Python, install it. ... .
Install Python. Once the installer is downloaded, do the following steps: ... .
Install the Microsoft ODBC Driver for SQL Server on Windows..
Open cmd.exe as an administrator..
Install pyodbc using pip - Python package manager. cmd Copy..

How do I know if I have ODBC driver 17 for SQL Server installed?

Open the Windows Control Panel. Open the Administrative Tools folder. Double-click Data Sources (ODBC) to open the ODBC Data Source Administrator window. Click the Drivers tab and locate the SQL Server entry in the list of ODBC drivers to confirm that the driver is installed on your system.

What is the ODBC driver 17 for SQL Server?

The Microsoft ODBC Driver 17 for SQL Server provides native connectivity from Windows, Linux, & macOS to SQL Server and Azure SQL Databases. Note that this driver supports SQL Server 2019 only from version 17.3. More info about this driver can be found at the Microsoft product page.

How do I install ODBC driver manager?

Go to Start > Settings > Control Panel..
Open the ODBC icon..
The User DSN tab appears. Click Add..
The Create New Data Source window appears. Select the appropriate driver and click Finish. ... .
The Data Source Setup window appears for that driver. ... .
Click Select..
The Select Database window opens. ... .
Click OK..

Toplist

Latest post

TAGs