tobania / VSTS.Extension.SqlReportingServices

VSTS Extension for uploading SSRS Reports
MIT License
14 stars 20 forks source link

Issue with DataSource #45

Open joemorin73 opened 5 years ago

joemorin73 commented 5 years ago

There appears to be some issues when updating Shared Datasources in the Reports:

    <DataSource Name="PRODSQL">
      <DataSourceReference>PRODSQLSRC</DataSourceReference>
      <rd:SecurityType>None</rd:SecurityType>
      <rd:DataSourceID>d8e06de5-dc11-494d-9d11-a6d29ccb30c8</rd:DataSourceID>
    </DataSource>
  </DataSources>
Foreach($serverDataSource in $serverDataSources){
    if([System.String]::Compare($serverDataSource.Name.Trim(),$reportDataSourceName.Trim(),$true) -eq 0){
        $dataSourcePathNew = $serverDataSource.Path;

        Write-Host "Updating DataSource '$reportDataSourceName' to path '$dataSourcePathNew'..." -NoNewline;

        $dataSourceReferenceNew = New-Object("$type.DataSourceReference");
        $dataSourceReferenceNew.Reference = $dataSourcePathNew;

        $dataSourceNew = New-Object ("$type.DataSource");
        $dataSourceNew.Name =$reportDataSourceName;
        $dataSourceNew.Item = $dataSourceReferenceNew;
        #[System.Collections.Generic.List[$type + ".DataSource"]]$arr = @($dataSourceNew);
        $ssrs.SetItemDataSources($report.Path,$dataSourceNew);
        Write-Host "Done!";
        break;
    }
}

In the if Statement, $reportDataSourceName is being compared to the DataSource names. This won't work if the reports DataSource name is different than the shared DataSource's name. (Example, If is looking for PRODSQL, but only PRODSQLSRC exists. It will never be found.)

$reportDataSourceName = $_.Name should be changed to $reportDataSourceName = $_.DataSourceReference.

Additional minor point, I'm not sure if it would be needed, but you may need to strip any path to the reference. (If it exists.)