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

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

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?

回答1:

Running:

odbcinst -j 

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/odbci.ini 

This solved the problem!



回答2:

In my case, I have to change the pyodbc database driver string to
driver='{ODBC Driver 17 for SQL Server}'

actually, in my python code pyodbc was expecting ODBC Driver 13
but, as the ODBC Driver version was updated (because of ubuntu update) to current version ODBC Driver 17, the problem was occurred.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!