Cant open lib sql server

Environment

  • Python: 3.9.7
  • pyodbc: 4.0.32
  • OS: MacOS 12.0.1, Apple M1 Max
  • DB: Azure SQL
  • driver: ODBC Driver 17 for SQL Server

Issue

When running

Show
import pyodbc

server = 'xxx.database.windows.net'
database = 'yyy'
username = 'zzz'
password = '???
odbc_driver = '{ODBC Driver 17 for SQL Server}'
conn_str = f'DRIVER={odbc_driver};SERVER=tcp:{server};PORT=1433;DATABASE={database};UID={username};PWD={password}'

print('opening....')
cnn = pyodbc.connect(conn_str)
print("opened")

I get

  File "/Users/deniz/OneDrive/Dev/webhook_receiver/sql.py", line 12, in <module>
    cnn = pyodbc.connect(conn_str)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

output:

opening....
[ODBC][95553][1650740040.206997][__handles.c][460]
		Exit:[SQL_SUCCESS]
			Environment = 0x7fb930024c00
[ODBC][95553][1650740040.207022][SQLSetEnvAttr.c][189]
		Entry:
			Environment = 0x7fb930024c00
			Attribute = SQL_ATTR_ODBC_VERSION
			Value = 0x3
			StrLen = 4
[ODBC][95553][1650740040.207060][SQLSetEnvAttr.c][381]
		Exit:[SQL_SUCCESS]
[ODBC][95553][1650740040.207073][SQLAllocHandle.c][377]
		Entry:
			Handle Type = 2
			Input Handle = 0x7fb930024c00
		UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UCS-2-INTERNAL'

[ODBC][95553][1650740040.207119][SQLAllocHandle.c][513]
		Exit:[SQL_SUCCESS]
			Output Handle = 0x7fb930029600
[ODBC][95553][1650740040.207368][SQLDriverConnectW.c][290]
		Entry:
			Connection = 0x7fb930029600
			Window Hdl = 0x0
			Str In = [DRIVER={ODBC Driver 17 for SQL Server};SERVER=tcp:xxx.database.windows.net;PORT=1433;DATABASE=yyy...][length = 166 (SQL_NTS)]
			Str Out = 0x0
			Str Out Max = 0
			Str Out Ptr = 0x0
			Completion = 0
[ODBC][95553][1650740040.209211][SQLConnect.c][1140]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found
[ODBC][95553][1650740040.209244][SQLDriverConnect.c][748]
		Entry:
			Connection = 0x7fb930029600
			Window Hdl = 0x0
			Str In = [DRIVER={ODBC Driver 17 for SQL Server};SERVER=tcp:xxx;PORT=1433;DATABASE=yyy...][length = 166 (SQL_NTS)]
			Str Out = 0x3076d55c0
			Str Out Max = 2048
			Str Out Ptr = 0x0
			Completion = 0
[ODBC][95553][1650740040.209362][SQLConnect.c][1140]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found
[ODBC][95553][1650740040.209384][SQLGetDiagRecW.c][535]
		Entry:
			Connection = 0x7fb930029600
			Rec Number = 1
			SQLState = 0x3076d7964
			Native = 0x3076d794c
			Message Text = 0x7fb93003a600
			Buffer Length = 1023
			Text Len Ptr = 0x3076d7962
[ODBC][95553][1650740040.209410][SQLGetDiagRecW.c][596]
		Exit:[SQL_SUCCESS]
			SQLState = [01000]
			Native = 0x3076d794c -> 0 (32 bits)
			Message Text = [[unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found]
[ODBC][95553][1650740040.209439][SQLFreeHandle.c][290]
		Entry:
			Handle Type = 2
			Input Handle = 0x7fb930029600
[ODBC][95553][1650740040.209451][SQLFreeHandle.c][339]
		Exit:[SQL_SUCCESS]

How can I fix this?

check Best Answer

  • Cant open lib sql server

    datil

    General Linux Expert

    • check 89 Best Answers
    • thumb_up 187 Helpful Votes

    checkBest Answer

    The permission settings on the sym link are irrelevant.  What are the permissions on the file(s) pointed to?

    Also, make sure users have access permission (x) to all directories in the path.

    Was this post helpful? thumb_up thumb_down

  • View Best Answer in replies below

    10 Replies

    • Cant open lib sql server

      Right, and here's what I get from running the following commands:

      odbcinst -j

      Text

      unixODBC 2.3.7
      DRIVERS............: /usr/local/etc/odbcinst.ini
      SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
      FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
      USER DATA SOURCES..: /usr/local/etc/odbc.ini
      SQLULEN Size.......: 8
      SQLLEN Size........: 8
      SQLSETPOSIROW Size.: 8
      

      cat /etc/odbcinst.ini

      Text

      [ODBC Driver 13 for SQL Server]
      Description=Microsoft ODBC Driver 13 for SQL Server
      Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2
      UsageCount=1
      
      [ODBC Driver 17 for SQL Server]
      Description=Microsoft ODBC Driver 17 for SQL Server
      Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.5.so.2.1
      UsageCount=1
      

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      Oh and we made these links too:

      Text

      sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
      

      Text

      sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini
      

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      Can your normal user account read those files in both locations (/etc and /usr/local/etc)? Check each one. Your error message indicates it cannot find the file(s) and that indicates a permission or link issue.

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      I'm running it from my normal user account. Shouldn't making those links negate permission issues though?

      I tried running my code as sudo su to see what happens and I get a different error:

      Text

      pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
      

      I'm not sure what that tells me. It's using the 13 driver which is good, but does a time out mean it's never even reaching the database? The credentials shouldn't be getting rejected because they work just fine on windows machines.

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      Timeout expired usually indicates the connection parameters or server name resolution is bad.

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      yeah, I went into my code and changed the server name to it's ip address and it didn't have any trouble running my code as sudo! So I learned two things:

      1. the "ODBC Driver 13 for SQL Server" can only be accessed by root (so I'll fix that)
      2. you need to use ip address not server names (so I'll just have my developer change her code too)

      So I just gotta figure out what to do about point 1. Why do my sym links not work? Shouldn't they allow non-root users to follow them??? Is it because I made them as sudo?

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      datil

      General Linux Expert

      • check 89 Best Answers
      • thumb_up 187 Helpful Votes

      checkBest Answer

      The permission settings on the sym link are irrelevant.  What are the permissions on the file(s) pointed to?

      Also, make sure users have access permission (x) to all directories in the path.

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      Oh okay I understand the sym link now, nvm how I thought it worked 😂

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      furicle

      Cant open lib sql server

      This person is a verified professional.

      Verify your account to enable IT peers to see that you are a professional.

      thai pepper

      I'd be surprised if you have to use IP address - I'd look into the DNS settings on that box rather than force a code change...

      Was this post helpful? thumb_up thumb_down

    • Cant open lib sql server

      Okay looks like I got the permissions all fixed up, driver is working fine without sudo now. Thanks so much for letting me bounce my ideas around the forums again!

      Was this post helpful? thumb_up thumb_down