简体   繁体   English

在Jupyter Notebook中连接到SQL DB时出现错误

[英]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. 与SQL DB连接时在jupyter上遇到以下代码的问题。

    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)')

Assumed that you are using Microsoft Azure Notebooks , I tried to reproduce your issue successfully, as below. 假设您使用的是Microsoft Azure笔记本 ,我尝试成功重现您的问题,如下所示。

在此处输入图片说明

It was caused by the connection string you used. 这是由您使用的连接字符串引起的。

On Azure portal, you will see three ODBC connection string, as the figure below. 在Azure门户上,您将看到三个ODBC连接字符串,如下图所示。

在此处输入图片说明

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 显然,您正在尝试使用第二个用户,该用户需要一个Azure Active Directory帐户的用户名和密码,如官方文档“ 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} . 并且根据同一文档,ODBC驱动程序版本13.1似乎不支持此身份验证方式,请更改为将ODBC驱动程序版本17与{ODBC Driver 17 for SQL Server}

在此处输入图片说明

And first, please check msodbcsql17 which has been installed. 首先,请检查已安装的msodbcsql17

在此处输入图片说明

However, I tried to connect using msodbcsql17 , it failed by login timeout error. 但是,我尝试使用msodbcsql17进行连接,但由于登录超时错误而失败。 Even I tried to upgrade pyodbc from 3.1.1 to 4.0.26 via !pip install pyodbc --upgrade 甚至我也尝试通过!pip install pyodbc --upgrade 4.0.26pyodbc3.1.1升级到4.0.26

在此处输入图片说明

So please try and may get the successful connection, if you have to authenticate AAD for SQL Database connection. 因此,如果必须对SQL数据库连接的AAD进行身份验证,请尝试并获得成功的连接。 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. 或切换到第一种连接方式,以使用SQL数据库用户名和密码通过pyodbc==3.1.1 (升级到4.0.26 ,这将导致另一个错误)和{ODBC Driver 13 for SQL Server} ,它对我4.0.26

在此处输入图片说明

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在运行 jupyter notebook 时出现错误? - Why am I getting an error while running jupyter notebook? 尝试在 jupyter 笔记本中打印 json 数据时,出现 JSON 解码错误? - While trying to print the json data in jupyter notebook, I am getting JSON decode error? Jupyter Notebook:连接到服务器时出错 - Jupyter Notebook: Error while connecting to Server 我正在尝试运行 jupyter notebook。 但收到以下错误: - I am trying to run jupyter notebook. but getting the following error: 在 jupyter notebook 中运行时出错 - Getting error while running in jupyter notebook 在jupyter中读取csv文件时出现错误 - i am getting error while reading the csv file in jupyter 为什么在 jupyter 笔记本上读取 pdf 文件时出现文件未找到错误? - Why am I getting a file not found error when reading a pdf file on jupyter notebook? 在 Jupyter Notebook 中使用 SnowFlake 连接到 MySQL DB - Connecting to a MySQL DB with SnowFlake in a Jupyter Notebook 从 Jupyter Notebook 连接到 Db2 的问题 - Issues connecting to Db2 from Jupyter Notebook 为了将 chrome 设置为 jupyter 的默认浏览器,我在运行配置文件时遇到错误 - jupyter_notebook_config.py - In order to set chrome as default browser for jupyter , i'm getting error while running config file- jupyter_notebook_config.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM