I am attempting to connect to SQL Server using a simple python script that looks like the following.
import pyodbc
details = {
'server': '<hostname>',
'database': '<database>',
'username': '<username>',
'password': '<password>'
}
connect_string = 'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server};PORT=1443;DATABASE={database};UID={username};PWD={password}'.format(**details)
connection = pyodbc.connect(connect_string)
print(connection)
The only difference is that I have removed the config value for obvious reasons. However, when I run this script I get the following error:
Traceback (most recent call last):
File "connect.py", line 12, in <module>
connection = pyodbc.connect(connect_string)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
For reference the output of runnning odbcinst -j
gives me:
unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/bipvanwinkle/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
cat /etc/odbcinst.ini
:
[SQLServer]
Description = ODBC Driver 17 for SQL Server
Driver = /usr/lib/x86_64-linux-gnu/libodbc.so
Setup = /usr/lib/x86_64-linux-gnu/libodbc.so.1
UsageCount = 1
FileUsage = 1
cat /etc/odbc.ini
:
[SQLServer]
Description = ODBC Driver 17 for SQL Server
Driver = /usr/lib/x86_64-linux-gnu/libodbc.so
Servername =
Database =
UID =
Port = 1433
ls /usr/lib/x86_64-linux-gnu/libodbc.so
:
/usr/lib/x86_64-linux-gnu/libodbc.so
ldd /usr/lib/x86_64llinux-gnu/libodbc.so
:
linux-vdso.so.1 (0x00007ffc86bec000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f9841306000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f98410e7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9840cf6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9840af2000)
/lib64/ld-linux-x86-64.so.2 (0x00007f984177d000)
If it helps, both /etc/odbcinst.ini and /etc/odbc.ini were initially empty. I used a template I found online to fill them out. I definitely could have made errors.
Any ideas where I've gone wrong?
P.S. I'm running this on Ubuntu 17.10