7

I'm on Ubuntu 16.04 trying to use sqlcmd launched programmatically from a script to do a SQL query in the VM's cloud.

vm-dev:~$ sudo sqlcmd -S my-db.url.net -d my-db

I keep getting this error:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1' : file not found.

But the file is clearly there:

vm-dev:~$ ls /opt/microsoft/msodbcsql17/lib64/

libmsodbcsql-17.0.so.1.1

Hack-R
  • 22,422
  • 14
  • 75
  • 131

3 Answers3

8

Just for those who are experiencing the same issue on Ubuntu 18.04 and came here but didn't have the issue solved by the accepted answer, since it's targeted to Ubuntu 16.04, sharing another possible solution, tested with an Ubuntu 18.04 docker container for a Python 3.6 application which relies on Microsoft's odbc driver.

Step 1: Check Library Dependencies

Check if all library dependencies are satisfied using the command ldd. On my environment, the missing libraries were libssl1.0.0 and libgssapi-krb5-2. Below, an example of the command and its output with a missing dependency, grep the output for not found if you will.

$ ldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1 

libfoo.so => /path/to/lib/foo/libfoo.so
libbar.so => /path/to/lib/bar/libbar.so
libbaz.so => not found

Step 2: Check Who Provides the Missing Dependency

Check which package provides the missing dependency using dpkg search.

$ dpkg -S libbaz.so

libbaz:amd64: /usr/lib/x86_64-linux-gnu/libbaz.so.1.2.3,

Step 3: Install Missing Dependency

$ sudo apt install libbaz
dandev486
  • 4,143
  • 2
  • 14
  • 22
  • This worked for me, however de missing dependency was libgssapi_krb5.so.2, which could not be found with dpkg -S. In stead I looked for it at https://packages.ubuntu.com/ – Daan Jun 23 '22 at 13:04
7

I have same problem, this solution worked for me: you have to downgrade the msodbcsql version,

  1. apt-get remove msodbcsql
  2. apt-cache madison msodbcsql
  3. apt-get install msodbcsql=13.1.9.2-1
  4. apt-cache madison mssql-tools
  5. ACCEPT_EULA=Y apt-get install mssql-tools=14.0.6.0-1
  6. apt-mark hold mssql-tools
  7. apt-mark hold msodbcsql

I got this solution from this link:

https://github.com/Microsoft/msphpsql/issues/684

Diyar
  • 469
  • 3
  • 12
0

I leave this scripts that worked for me.

My problem was pretty similar yours and I tested all the options such as changing the driver location, making a symbolic link, modify /etc/*.ini files, etc... nothing worked.

My problem, running python 3.6, pyodbc package in a docker container from alpine was the library libssl1.0.0

Here you will find my installation script for pyodbc Debian 8 (alpine) docker image using the driver v13

DRIVER={ODBC Driver 13 for SQL Server}

The command I run for database connection was:

import pyodbc
connection_string = 'DRIVER={ODBC Driver 13 for SQL Server};'
connection_string += 'SERVER={0};DATABASE={1};UID={2};PWD={3};'.format(host,dbname,user,pwd)
connection = pyodbc.connect(connection_string)
nenetto
  • 354
  • 2
  • 6