Skip to content Skip to sidebar Skip to footer

I Am Getting An Error While Connecting To An Sql Db In Jupyter Notebook

Facing issue with below code on jupyter while connecting with SQL DB. con = pyodbc.connect('Driver={ODBC Driver 13 for SQL Server};Server='+server+';Database='+database+';

Solution 1:

Assumed that you are using Microsoft Azure Notebooks, I tried to reproduce your issue successfully, as below.

enter image description here

It was caused by the connection string you used.

On Azure portal, you will see three ODBC connection string, as the figure below.

enter image description here

Obviously, you are trying to use the second one which required the username and password of an Azure Active Directory account, as the figure said from the offical document Using Azure Active Directory with the ODBC Driver

enter image description here

And according to the same document, the ODBC Driver version 13.1 seems to not support this authentication way, please change to use ODBC Driver version 17 with {ODBC Driver 17 for SQL Server}.

enter image description here

And first, please check msodbcsql17 which has been installed.

enter image description here

However, I tried to connect using msodbcsql17, it failed by login timeout error. Even I tried to upgrade pyodbc from 3.1.1 to 4.0.26 via !pip install pyodbc --upgrade

enter image description here

So please try and may get the successful connection, if you have to authenticate AAD for SQL Database connection. Or switch to the first connection way, to use SQL Database username and password to connect by pyodbc==3.1.1(upgrade to 4.0.26 that will cause another error) and {ODBC Driver 13 for SQL Server}, it works for me.

enter image description here

Hope it helps.

Post a Comment for "I Am Getting An Error While Connecting To An Sql Db In Jupyter Notebook"