Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?

Tags:

python

pyodbc

When I try to connect to a sql server database with pyodbc (on mac):

import pyodbc  server = '####' database = '####' username = '####@####' password = '#####' driver='{ODBC Driver 13 for SQL Server}'  pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+password) 

I get the following error:

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

When I path in the actual driver location:

driver='/usr/local/lib/libmsodbcsql.13.dylib' 

It starts working!

My odbcinst.ini looks like this:

[ODBC Driver 13 for SQL Server] Description=Microsoft ODBC Driver 13 for SQL Server Driver=/usr/local/lib/libmsodbcsql.13.dylib UsageCount=1 

How can I get my reference to driver='{ODBC Driver 13 for SQL Server}' to start working again?

I initially used this guide to install the driver. And I'm using anaconda on Mac Sierra if that helps?

like image 371
emehex Avatar asked Jun 13 '17 16:06

emehex


People also ask

How do I fix ODBC connection failed in SQL Server?

Resolving The Problem. When you create the ODBC connection to SQL server, select the option of With SQL Server authentication using a login ID and password entered by the user. Also, confirm that in Microsoft Access, the Machine Data Source and System Data Source has been used to create the ODBC connection.

What is ODBC driver 13 SQL Server?

The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows + Linux to Microsoft SQL Server and Microsoft Azure SQL Database. Details. Note: There are multiple files available for this download. Once you click on the "Download" button, you will be prompted to select the files you need.


2 Answers

Running:

odbcinst -j 

It yielded:

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

Instead of copying the files to the /etc/ directory (not sure why unixODBC thought they were there) I created a symbolic link to each file:

sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini 

This solved the problem.

like image 78
emehex Avatar answered Sep 27 '22 19:09

emehex


In my case, I have a Mac OS and the following commands fixed the problem:

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update brew install msodbcsql mssql-tools 

Note 1: It might be necessary that you need to install unixodbc in advance to msodbcsql and mssql-tools as the following:

brew install unixodbc 

Note 2: If you dont have already brew, the Missing Package Manager for macOS, then you can install it from here: https://brew.sh/

Note 3: You can verifiy your installation as @emehex already mentioned above with the following commands:

odbcinst -j  sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini 
like image 44
Rene B. Avatar answered Sep 27 '22 21:09

Rene B.