I am getting an error while connecting to an sql DB in Jupyter Notebook

北城余情 提交于 2020-01-16 16:57:31

问题


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+';Uid='+username+'
    ;Pwd='+passwor 
    d+';Encrypt=yes;TrustServerCertificate=no;Connection 
    Timeout=30;Authentication=ActiveDirectoryPassword')

    Error Description Below:
    OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 13 for SQL 
    Server]SSL Provider: [error:140A90F1:lib(20):func(169):reason(241)] (-1) 
    (SQLDriverConnect)')

回答1:


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

It was caused by the connection string you used.

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

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

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}.

And first, please check msodbcsql17 which has been installed.

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

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.

Hope it helps.



来源:https://stackoverflow.com/questions/56866757/i-am-getting-an-error-while-connecting-to-an-sql-db-in-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!