【问题标题】:Is it possible to use pyodbc to export data from a Power BI Datamart?是否可以使用 pyodbc 从 Power BI 数据集市导出数据?
【发布时间】: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


【解决方案1】:

我刚刚检查了一下,目前确实对此功能有限制(仍处于预览状态)。正如 here 所述,只有 SSMS 版本 18 才能连接到数据集市,因为它包含一个列入白名单的 applicationId。

但是,即使 pyodbc 是受支持的类型,您的代码也永远不会运行,因为 azure ad auth 是唯一受支持的身份验证方法。请参阅here,这在理论上是如何工作的(适用于任何其他 azure sql 实例)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多