【发布时间】:2022-12-14 13:25:45
【问题描述】:
我读过 Power BI 数据集市在本质上是一个 Azure SQL 数据库。因此,我认为可以使用 Python 的 pyodbc 包从 Power BI 数据集市中提取数据。
我按照 Microsoft 的快速入门教程连接到 Azure SQL 数据库,但未能深入了解它。鉴于我是 Python 的新手,我想知道我的失败是否与实际限制有关,或者这是否只是我糟糕的代码。
这是我的代码:
server = 'xxxxxxxxxxxxx.datamart.pbidedicated.windows.net'
database = 'xxxxxxxxxx'
username = 'email@xxxxxxxx.com'
password = 'xxxxxxxxxx'
driver= 'ODBC Driver 18 for SQL Server'
with pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT TOP 3 name, collation_name FROM sys.databases")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
我得到的错误如下:
OperationalError: ('08S01', '[08S01] [Microsoft][SQL Server 的 ODBC 驱动程序 18]TCP 提供程序:现有连接被远程主机强行关闭。\r\n (10054) (SQLDriverConnect); [08S01] [Microsoft][SQL Server 的 ODBC 驱动程序 18]通信链接失败 (10054);[08S01] [Microsoft][SQL Server 的 ODBC 驱动程序 18]无效的连接字符串属性 (0)')
我四处寻找答案,但画的是空白。任何帮助深表感谢 :)
【问题讨论】:
-
看起来您想使用 azure ad auth 进行连接,或者只是您在示例中选择的一个奇怪的用户名?
标签: python powerbi azure-sql-database pyodbc