[英]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.26
将pyodbc
从3.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.