Cocoa Krispy's
Cocoa Krispy's

Reputation: 11

Why do I not have ODBC Driver 17 in my pyodbc drivers? How can I fix this in anaconda?

I keep getting this error when trying to connect to SQL server through pyodbc:

pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

This is the string I am passing through pyodbc.connect():

'DRIVER={ODBC Driver 17 for SQL Server};'

When I run print(pyodbc.drivers()), this is what is returned:

['SQL Server', 'Microsoft Access Driver (*.mdb, *.accdb)', 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)', 'Microsoft Access Text Driver (*.txt, *.csv)']

How can I get the ODBC driver 17 to appear in my list of pyodbc drivers? For reference, I am running anaconda on windows on my work machine.

Many thanks

Upvotes: 1

Views: 7104

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123654

The list returned by pyodbc.drivers()

['SQL Server',
 'Microsoft Access Driver (*.mdb, *.accdb)',
 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)',
 'Microsoft Access Text Driver (*.txt, *.csv)'
]

… indicates that the process is running under 64-bit Python on Windows because it doesn't include the legacy 32-bit Jet drivers like Microsoft Access Driver (*.mdb) that are automatically installed by the Windows setup program. Therefore we can conclude that the 64-bit version of ODBC Driver 17 for SQL Server simply wasn't installed on that machine. Installing it via

https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server

resolved the issue.

Upvotes: 2

Related Questions