0

I am trying to get the data from my SQL Azure Database. It seems like my python code throws the error because of linking confusion with ODBC Drivers.

Here is my Python code.

from urllib import parse
from sqlalchemy import create_engine

connecting_string = 'Driver={ODBC Driver 13 for SQL Server};Server=tcp:mftaccountinghost.database.windows.net,1433;Database=mft_accounting;Uid=localhost;Pwd=######;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30'
params = parse.quote_plus(connecting_string)

engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)
connection = engine.connect()
result = connection.execute("select 1+1 as res")
for row in result:
    print("res:", row['res'])
connection.close()

Here is the error I get:

sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libmsodbcsql.13.dylib' : file not found (0) (SQLDriverConnect)")

When I check my terminal I get the following results. Cannot resolve this issue...

Terminal

Here is my connection string for the server:

Connstr

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • what's ODBC driver version have you installed? Did you tried to update to ODBC driver 17? Then the connection string should be start with `Driver={ODBC Driver 17 for SQL Server}…`. – Leon Yue Dec 25 '19 at 01:12

1 Answers1

0

Here is complete guide to install the ODBC driver in UNIX machine:

https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

If you installed the v17 msodbcsql package that was briefly available, you should remove it before installing the msodbcsql17 package. This will avoid conflicts.

Try uninstalling the driver and install it again it should work.

Also check below thread for additional reference:

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

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27