Skip to content

[DOC] Installing ODBC Driver 17 for SQL Server #243

@Eric-Liu-SANDAG

Description

@Eric-Liu-SANDAG

Describe the documentation fix or enhancement

In Python code, in order to connect to the SQL Servers, we use the following style of connection string:

ESTIMATES_ENGINE = sql.create_engine(
"mssql+pyodbc://@"
+ _secrets["sql"]["estimates"]["server"]
+ "/"
+ _secrets["sql"]["estimates"]["database"]
+ "?trusted_connection=yes&driver="
+ "ODBC Driver 17 for SQL Server",
fast_executemany=True,

Note, the connection string requires that ODBC Driver 17 for SQL Server is installed on the computer, which is not necessarily the case. This results in the error message:

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

The particular driver is also not installed by uv, despite pyodbc being specified in pyproject.toml. In order to solve this issue, I undertook the following steps which should be properly documented in the Setup section of README.md

First, check if ODBC Driver 17 for SQL Server is installed by running the program odbcad32.exe. It can be found using the Windows search bar. In the new screen, navigate to the Drivers page to see installed drivers
Image

As you can see, ODBC Driver 17 for SQL Server is not installed. Note, ODBC Driver 18 for SQL Server does not work in the connection string as a different error will be raised. Follow the instructions from pyodbc to install the proper driver (Note, link is a permalink and may not be the most recent wiki revision)

Afterwards, you can see ODBC Driver 17 for SQL Server appears in the list of installed drivers (you may have to close and reopen the odbcad32.exe screen)
Image

And code executes without the error message

Metadata

Metadata

Labels

No labels
No labels
No fields configured for Documentation.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions