When I try to connect to a sql server database with pyodbc (on mac):
JavaScript
x
10
10
1
import pyodbc
2
3
server = '####'
4
database = '####'
5
username = '####@####'
6
password = '#####'
7
driver='{ODBC Driver 13 for SQL Server}'
8
9
pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+password)
10
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:
JavaScript
1
2
1
driver='/usr/local/lib/libmsodbcsql.13.dylib'
2
It starts working!
My odbcinst.ini
looks like this:
JavaScript
1
5
1
[ODBC Driver 13 for SQL Server]
2
Description=Microsoft ODBC Driver 13 for SQL Server
3
Driver=/usr/local/lib/libmsodbcsql.13.dylib
4
UsageCount=1
5
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?
Advertisement
Answer
Running:
JavaScript
1
2
1
odbcinst -j
2
It yielded:
JavaScript
1
9
1
unixODBC 2.3.4
2
DRIVERS : /etc/odbcinst.ini
3
SYSTEM DATA SOURCES: /etc/odbc.ini
4
FILE DATA SOURCES..: /etc/ODBCDataSources
5
USER DATA SOURCES..: /Users/emehex/.odbc.ini
6
SQLULEN Size .: 8
7
SQLLEN Size ..: 8
8
SQLSETPOSIROW Size.: 8
9
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:
JavaScript
1
3
1
sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
2
sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini
3
This solved the problem.