0

I can't connect to MS SQL Server in my Jupyter notebook:

Code:

import pyodbc
pyodbc.drivers()

Output:

[]

Nothing!

Connection string:

db_connection = pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};'
                               'Server=Server IP;'
                               'Database=DB_Main;'
                               'UID=DB_User;'
                               'PWD=secrets')

Every conceivable driver string I use I get the same basic message:

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

Since pyodbc.drivers() isn't showing anything it would seem that the installation is borked.

UPDATE: I was unable to get the symlink solutions with the INI files to work as suggested here: Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?

Directly specifying the driver as shown in the answer below is what worked.

Bubnoff
  • 3,917
  • 3
  • 30
  • 33
  • Did you find a solution? I'm having the same problem. – Evandro Pomatti Apr 23 '20 at 00:34
  • Does this answer your question? [Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?](https://stackoverflow.com/questions/44527452/cant-open-lib-odbc-driver-13-for-sql-server-sym-linking-issue) – Evandro Pomatti Apr 23 '20 at 01:10
  • @EvandroPomatti See my answer below. I tried all that stuff -- symlinks etc. Resorted to just directly specifying the driver -- see my answer below. I don't remember where I found this solution. – Bubnoff Apr 24 '20 at 15:29

2 Answers2

1

I ended up having to directly specify the driver like this:

driver = '/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so'
ip = "10.10.10.1"
db_connection = pyodbc.connect(
    driver = driver,
    Server = ip,
    Port = "49189",
    Database = "project_db",
    UID = "db_user",
    PWD = "secrets" )

Installed TDS and the ODBC packages on the server then searched for the libtdsodbc.so driver using find. This worked perfectly though there may be other simpler ways.

Bubnoff
  • 3,917
  • 3
  • 30
  • 33
  • 1
    I managed to get it working too and without specifying, if you want you may take a look here: https://github.com/evandropomatti/pyodbc-docker – Evandro Pomatti Apr 24 '20 at 16:32
0

Try Installing ODBC Drivers (13/17) and your pyodbc.drivers() should return the driver info, you should be able connect then.

dragnblow
  • 11
  • 2
  • 1
    Are you answering the main question or do you have another question? Please this space should be used only to post answers! – Steve Dec 25 '21 at 19:45
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30672180) – l33tHax0r Dec 27 '21 at 17:00