Forum Discussion
Publishing a Live Connection PBI Report to different environments
- 1 year ago
Hi JSkyrm
The issue you're facing, where your Power BI report fails to publish across environments due to a live connection tied to the Dev semantic model, is a common challenge when managing Power BI reports in multiple environments (Dev, Test, Demo, Prod). Since the live connection is hardcoded to reference the Dev semantic model, Power BI Service cannot find the model in the higher environments, causing the publishing process to fail. The key to resolving this issue lies in dynamically adjusting the report's dataset connections to point to the appropriate environment-specific semantic model. One approach is to parameterize the dataset connection in Power BI Desktop, where you can create parameters for server names or dataset identifiers, and modify their values based on the environment. This allows you to use the same .pbix file across environments without needing to duplicate it for each one. Another solution is to use PowerShell scripts or the Power BI REST API to automate the publishing and re-binding process, where you can programmatically reconfigure the connection to the correct semantic model after the report is deployed. Power BI Deployment Pipelines can also help by automating the deployment of reports and datasets across environments, ensuring the report is connected to the correct model in each stage of the pipeline. Additionally, creating Template Apps can streamline deployment by allowing environment-specific configuration without manual duplication. By leveraging these methods, you can eliminate the need to manually manage multiple copies of the report and ensure that it always connects to the right dataset in each environment, reducing maintenance overhead and improving deployment consistency.
We had a similar issue. We had a report connected to a dataset using a live-connection. We needed to repoint the live connection at a dataset in a different workspace (we needed to move it to a different Premium Capacity workspace). The main reason we needed to do this, is so that we wouldnt change the report URL that everyone was already using.
What we wanted:
Workspace A (Report A) --------> Workspace 1 (Dataset A)
After change:
Workspace A (Report A) --------> Workspace 2 (Dataset A')
Here is everything we tried:
1. Directly updating the dataset using the "Transform Data" >> "Datasource settings".
This seemed to work locally, but when we published the report back to its workspace, it magically created 2 reports with the exact same name. The original report remained untouched.
2. Rebinding using PowerShell
The code I used is at the bottom of this post. This worked! Except for one major issue. The report was repointed at the new dataset in the new workspace, but when we downloaded the PBIX file, it still was pointed at the dataset in the original workspace. This would not work, as we still need to continue to build the pages in this report.
3. Using PBIP file (this is the solution)
a. We downloaded the file from PowerBi.com and opened the file in PowerBi Desktop and saved it as a PBIP file.
b. Closed PowerBi desktop and in the folder where we saved the PBIP file, within the "xxxxx.Report" subfolder, we opened the "definintion.pbir" file and edited in NotePad. Specifically the "connection string" was updated:
Original pbir file:
{
"version": "4.0",
"datasetReference": {
"byConnection": {
"connectionString": "Data Source=\"powerbi://api.powerbi.com/v1.0/myorg/Workspace 1\";Initial Catalog=\"Dataset A\";Access Mode=readonly;Integrated Security=ClaimsToken",
"pbiServiceModelId": null,
"pbiModelVirtualServerName": "sobe_wowvirtualserver",
"pbiModelDatabaseName": "Dataset A's GUID",
"name": "EntityDataSource",
"connectionType": "pbiServiceXmlaStyleLive"
}
}
}PBIR file after update:
{
"version": "4.0",
"datasetReference": {
"byConnection": {
"connectionString": "Data Source=\"powerbi://api.powerbi.com/v1.0/myorg/Workspace 2\";Initial Catalog=\"Dataset A'\";Access Mode=readonly;Integrated Security=ClaimsToken",
"pbiServiceModelId": null,
"pbiModelVirtualServerName": "sobe_wowvirtualserver",
"pbiModelDatabaseName": "Dataset (A')'s GUID",
"name": "EntityDataSource",
"connectionType": "pbiServiceXmlaStyleLive"
}
}
}
c. Opened the PBIP file in Desktop and saved the file as PBIX (this step is not really needed).
d. Published the report back to Workspace A. Voila, the original report was now repointed at Dataset A` in Workspace 2.
PowerShell script used to rebind report
#report details that needs to be rebound
$reportWorkspaceName = "Workspace 1"
$reportName = "Report 1"
#new dataset details that report needs to be bound to
$datasetWorkspaceName = "Workspace 2"
$datasetName = "Dataset A`"
function RebindReport{
param(
[string]$workspaceId,
[string]$reportId,
[string]$datasetIdToRebindTo
)
if ($workspaceId -eq $null -or $reportId -eq $null -or $datasetIdToRebindTo -eq $null)
{
throw "WorkspaceId, ReportId, and DatasetIdToRebindTo must be specified"
}
$ApiUrl = "https://api.powerbi.com/v1.0/myorg/groups/${workspaceId}/reports/${reportId}/Rebind"
$ApiRequestBody = "{'datasetId': '${datasetIdToRebindTo}'}"
$ApiRequestBody
$response = $null
try
{
Write-Host "Rebinding Report"
$response = Invoke-PowerBIRestMethod -Url $ApiUrl -Method Post -Body ($ApiRequestBody)
Write-Host "Rebind completed"
Write-Host "Complete"
}
catch
{
Write-Host "An error occurred:"
Write-Host $_
}
$response
}
$ErrorActionPreference = "Stop"
Login-PowerBI | Out-Null
#report info
$WorkspaceObject = (Get-PowerBIWorkspace -Name $reportWorkspaceName)
$PbiReportObject = (Get-PowerBIReport -Workspace $WorkspaceObject -Name $reportName)
$reportWorkspaceId = $WorkspaceObject.Id
$reportId = $PbiReportObject.Id
$oldDatasetForReport = $PbiReportObject.DatasetId
#dataset to rebind to info
Write-Host "Getting info for dataset ${datasetName} in ${datasetWorkspaceName}"
$datasetWorkspaceObject = (Get-PowerBIWorkspace -Name $datasetWorkspaceName)
#$PbiDatasetObject = (Get-PowerBIDataset -Workspace $datasetWorkspaceObject -Name $datasetName -Scope Individual)
$PbiDatasetObject = (Get-PowerBIDataset -Workspace $datasetWorkspaceObject) | Where-Object {$_.Name -eq $datasetName}
$PbiDatasetObject
$datasetWorkspaceId = $datasetWorkspaceObject.Id
$datasetId = $PbiDatasetObject.Id
Write-Host "Rebinding ReportId: ${reportId}"
Write-Host "in workspace ${reportWorkspaceId}"
Write-Host "from ${oldDatasetForReport}"
Write-Host "to ${datasetId} in ${datasetWorkspaceId}"
RebindReport -workspaceId $reportWorkspaceId -reportId $reportId -datasetIdToRebindTo $datasetId
$PbiReportObject = (Get-PowerBIReport -Workspace $WorkspaceObject -Name $reportName)
$PbiReportObject