-1

I currently have a late 2011 MacBook Pro, but I've done a few modifications...she now has 2 TB SSD installed internally, along with 16GB of RAM. The OS has been upgraded to Catalina 10.15.7. Im currently working with Python 3.7 via an anaconda3 setup with Jupyter Notebook. I'm convinced it is not an access/firewall issue b/c I can connect to the Azure SQL database via a VM and SQL Server, as well as through VS Code2 or PyCharm 2024.

I need to modify my current Python script to access the Azure SQL db, which I've done but I'm having a devil of a time connecting successfully!

I've attached screen shots of my terminal to show the odbcinst.ini file can be read/queried and return the correct configuration which I've managed to update based on the countless resources and similar questions asked. The /usr/local/lib/libmsodbcsql.17.dylib file pyodbc is looking for has a symlink and is shown on the last few lines of my terminal screenshot. This is the same path used to update the server name in the odbcinst.ini file. I've even provided screen shots of my .zshrc profile where I've explicitly defined the paths for "PATH" and "LD_LIBRARY_PATH" based on suggestion provided via StackOverflow. Again, unfortunately nothing has worked.

Please help.

TERMINAL ODBCINST.INI OUTPUT

ODBCINST.INI FILE CONFIGURATION

ODBC.INI FILE CONFIGURATION

.ZSHRC PROFILE UPDATE FOR ENVIRONMENT VARIABLE PATHS

JUPYTER NOTEBOOK PYTHON SCRIPT ATTEMPTS TO CONNECT USING PYODBC

ATTEMPTING TO CONNECT TO AZURE SQL DB VIA ANOTHER METHOD

ANOTHER ATTEMPT AT CONNECTING

3
  • Can't open lib '/usr/local/lib/libmsodbcsql.17.dylib' : file not found doesn't necessarily mean that that exact file cannot be found, i.e.: it could also be one of that file's dependencies. Does ldd /usr/local/lib/libmsodbcsql.17.dylib mention any missing files? Commented Apr 24, 2024 at 2:33
  • Aside... Homebrew isn't supported on macOS Catalina 10.15 any more. You will be receiving numerous "unsupported" warnings whenever you do a brew update or brew install. Commented Apr 24, 2024 at 2:34
  • Check this document to install the driver. learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/… Commented Apr 24, 2024 at 5:21

1 Answer 1

0
;' pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/user/local/lib/libmsodbcsql.17.dylib' : file not found (0) (SQLDriverConnect)")

If ODBC Driver 17 for SQL Server is not installed properly, then you may get the above error. Follow the MS Document to install the Microsoft ODBC driver for SQL Server (macOS). Along with that, use the code below to connect to the SQL Server using pyodbc:

import pyodbc

conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};'
                       '<serverName>;'
                       'DATABASE=<databaseName>;'
                       'UID=<userName>;'
                       'PWD=<password>')
cursor = conn.cursor()
cursor.execute("SELECT * FROM <tableName>")
rows = cursor.fetchall()
for row in rows:
    print(row)

It will connect successfully, as shown below:

enter image description here

For more information, you can refer to this.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.