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

前端 未结 9 1383
无人共我
无人共我 2020-11-27 12:20

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

import pyodbc

server = \'####\'
database = \'####\'
username = \'####@####\'
password =         


        
相关标签:
9条回答
  • 2020-11-27 12:54

    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.

    0 讨论(0)
  • 2020-11-27 12:56

    In my case, I had 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 had occurred.

    0 讨论(0)
  • 2020-11-27 12:57

    In my case, I fixed the problem with three steps as follow:

    # Step1: install unixodbc 
    brew install unixodbc
    
    # Step2: install Microsoft ODBC Driver for SQL Server on MacOS
    
    brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
    brew update
    brew install msodbcsql mssql-tools
    
    # Step3:verify odbcinst configuration path is correct
    
    odbcinst -j
    
    sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
    sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini
    
    0 讨论(0)
提交回复
热议问题