Skip to content
Advertisement

Building a connection URL for mssql+pyodbc with sqlalchemy.engine.url.URL

The problem…

I am trying to connect to a MSSql server via SQLAlchemy. Here is my code with fake credentials (not my real credentials obviously).

The code…

JavaScript

And this is the .pyodbc error that I am getting.

JavaScript

Additional Details

But, here is what is weird… I if make a pyodbc connection and use Pandas.read_sql, then I can get data without an error. So I do not understand why I am getting a ‘pyodbc’ error????

JavaScript

And then I can see the dataframe.

So, why am I getting the (pyodbc.Error) when I try to connect with SQLAlchemy?

System Information

JavaScript

Advertisement

Answer

As stated in the SQLAlchemy documentation, for mssql+pyodbc connections

When using a hostname connection, the driver name must also be specified in the query parameters of the URL.

JavaScript

For

JavaScript

your statement produces the connect_url

JavaScript

What you really need is

JavaScript

which produces

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement