以编程方式将 Power BI 报告部署到 Power BI 报告服务器并更改连接字符串

9
有没有方法可以在不手动复制文件、上传到服务器并逐个报告地更改数据源连接信息的情况下,将 Power BI 报告部署到 Power BI 报告服务器?这在每个客户站点都不切实际。例如,PowerBI 报告文件“Report_1”需要部署在客户服务器 S1、S2、S3 等上。现在我们正在手动复制这些文件,上传到服务器并最终逐个报告地更改数据源连接信息,这在每个客户站点都不切实际。我们如何自动化 PBIX 报告的部署到 Power BI 报告服务器,并通过编程方式更改数据源连接字符串?微软将在 2020 年 1 月发布使用 API 更新连接字符串的功能。

enter image description here

微软将在2020年1月发布新功能。但是有没有办法在2019年更新连接字符串?

微软链接


您可以使用Powershell进行部署。 - Jon
3个回答

3

最终发明了一种更新PowerBI连接字符串的技巧。

首先在Powershell中安装PowerBI API。 微软API不提供更新连接字符串的功能,但允许更新用户名。 用户名和连接字符串都以加密格式存储在数据库中。 所以将连接字符串传递给用户名,然后将加密字符串复制到数据库中的连接字符串列中。 请查看下面的示例,我编写并发明了这个技巧。谢谢。

# Code By SB 2019
$ReportServerURI = 'http://localhost/PowerBIReports' # Input Local path of powerbi file
$filePath = "C:\12.pbix"                                # Input Local path of powerbi file
$PBIxfileName = "12"                                    # INput your Powerbi File Name
$FolderName ='NewDataset'                               # Input PowerBI server Folder Name Where you wann to deploy
$Username ='admin'
$password ='password'                          
$ReportServerName ='localhost\SQl2017'                  #input SQL server where POWERBI database installed
$ReportServerDatabase = 'ReportServerPowerBI'           #input PowerBi Database Name 

$ConnectionString ='data source=Client01\SQL2019;initial catalog=Client_SB_1'  # input New Connection String / Client ConnectionString

$FolderLocation = '/'
$FolderPath = $FolderLocation + $FolderName

write-host "Deployment Started ..." -ForeGroundColor Yellow 
$session = New-RsRestSession -ReportPortalUri $ReportServerURI
Write-RsRestCatalogItem -WebSession $session -Path $filePath -RsFolder $folderPath -Description $Description -Overwrite
$datasources = Get-RsRestItemDataSource -WebSession $session -RsItem "$FolderPath/$PBIxfileName"
$dataSources[0].DataModelDataSource.AuthType = ‘Windows'
$dataSources[0].DataModelDataSource.Username = $ConnectionString 
$dataSources[0].DataModelDataSource.Secret = $password

Set-RsRestItemDataSource -WebSession $session -RsItem "$folderPath/$PBIxfileName" -RsItemType PowerBIReport -DataSources $datasources

$ID =  $dataSources[0].Id
$Query = " Update [DataModelDataSource] SET ConnectionString = Username From [dbo].[DataModelDataSource] Where DataSourceID ='" + $ID  + "' "

Invoke-Sqlcmd -Query $Query -ServerInstance CPMSUNRSQL17\CPMSRINST17 -Database ReportServerPowerBI

$datasources = Get-RsRestItemDataSource -WebSession $session -RsItem "$FolderPath/$PBIxfileName"
$dataSources[0].DataModelDataSource.Username = $Username
$dataSources[0].DataModelDataSource.Secret = $password
Set-RsRestItemDataSource -WebSession $session -RsItem "$folderPath/$PBIxfileName" -RsItemType PowerBIReport -DataSources $datasources

write-host "Deployment Done . . ." -ForeGroundColor Green 

0

只有当所需更改可以由参数驱动时,这才能起作用。例如,对于SQL Server源,可以设置数据库、模式或表名称(但不能设置服务器名称)。

首先,我将设置查询定义以使用查询参数,并进行测试。具体内容取决于您的数据源和场景-您没有提供任何信息。

然后,我将调用适当的REST API 更新参数方法-可能是Group版本。

https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/updateparametersingroup


你提供的链接是api.powerbi.com(PowerBI服务)。我的问题是关于安装在本地服务器的PowerBI服务器版本。我已经添加了详细说明。例如,我们可以使用更改数据源文件(XML格式)在多个客户端上部署一个SSRS报告,但PowerBI不支持此功能。PowerBI以二进制格式存储,并且Microsoft API不允许更新它。 - Mr. Bhosale

0

您可以使用ReportingServiceTools库通过Powershell将报告部署到Power BI Report Server,并更改连接和其他设置。由于Power BI Report Service是SSRS,因此可以使用相同的工具来加载报告,更改数据连接等。

部署文件的示例此处

您还可以直接在PBIX文件中更改连接设置。如果将扩展名从pbix更改为zip,则可以查看其中内容。

Power BI内部结构 如果打开“Connections”文件,它将通过JSON结构文件包含设置。

{"Version":1,"Connections":[{"Name":"EntityDataSource","ConnectionString":"Data Source=asazure://region.asazure.windows.net/somecubegoes her;Initial Catalog=SmartSpacesAnalysis;Cube=SmartSpacesModel","ConnectionType":"analysisServicesDatabaseLive"}]}

如果需要,可以读取和更改


我的PBIX是桌面文件而不是服务(Azure)。我已经尝试过Zip解压缩和PowerShell方法。谢谢您的评论。微软为Powerbi服务提供了所有功能,而不是为PowerBI桌面版提供。 - Mr. Bhosale
我也尝试过PowerShell。我们无法更新报告服务器桌面文件的连接字符串。 - Mr. Bhosale

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接