Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Implement Continuous Delivery for SQL Server Reporting Service Reports

$
0
0

By:Nat Sundar || Related Tips: > Reporting Services Development

Problem

What is Continuous Delivery and how do I implement Continuous Delivery for SQL Server Reporting Services Reports?

Solution Continuous Delivery

As per Martin Fowler, " Continuous Delivery is a software development discipline where you build software in such a way that the software can be released to production at any time.

There are two key elements to implement Continuous Delivery:

DevOps Culture Deployment Automation Continuous Integration vs. Continuous Delivery

CI (Continuous Integration) refers to the process of integrating, building, and testing for development purpose. However CD (Continuous Delivery) will help us to prepare the artifacts for the purpose of production deployment.

Deployment Automation

Deployment automation helps applications to deploy into multiple environments. This solution improves the productivity of both the Development and Operation teams.

Advantages of Deployment Automation Repeatability - Deployment to multiple environments is done using the same process Insight - Deployment related errors can be identified early in the process Low Risk - Completely remove the bottleneck of key resources (Developers) for the deployment

Most of the application release automation tools allow configuring a script to deploy. We have already learned to develop a PowerShell script to deploy the data source in the previoustip. In this tip we will learn to deploy the datasets and the reports using a PowerShell script. This script can be integrated with any release automation tool to enable Continuous Delivery for SQL Server Reporting Service Reports.

Deploying Shared Datasets

As same as the data source, the dataset can also be read as an XML object. This XML object will have the details about the Query, Columns and the data source. PowerShell can create a dataset object in the Reporting Services proxy with the help of an XML object. The CreateCatalogItem function can be used to create a dataset on the Reporting Services proxy.

Once the dataset has been created, the data source reference has to be updated. The SetItemDataSource function will help us to link the data source for the given dataset.

The script below is used to read and deploy the dataset to a remote Reporting Services Server.

$ReportServerUri = "http://localhost/ReportServer_SQL2012/ReportService2010.asmx?wsdl";
$DataSetFile = "C:\mssqlTips\Tips\SSRS_Deployment_Using_ps_Part3\Reference\Scripts\AdventureWorks Sample Reports\Currency.rsd";
$DataSourceFolder = "/MSSQLTips/Data Sources";
$DataSetFolder = "/Datasets";
try{
#Create Proxy
$global:proxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCredential
-ErrorAction Stop;
If ($proxy -ne $null)
{
echo $global:proxy.ToString();
}
#$DataSetFile = Get-Content -Path $DataSetFilePath
$DataSetName = [System.IO.Path]::GetFileNameWithoutExtension($DataSetFile);
$stream = [System.IO.File]::ReadAllBytes( $DataSetFile);
$warnings =@();
#Create dataset item in the server
try{
$newDataSet = $proxy.CreateCatalogItem("DataSet,$DataSetName,$DataSetFolder,
$true,$stream,$null,[ref]$warnings); }catch{ throw $_.Exception; }
[xml]$XmlDataSetDefinition = Get-Content $DataSetFile;
$xmlDataSourceReference = $XmlDataSetDefinition.SharedDataSet.DataSet | where {$_ | get-member Query};
try{ $dataSetDataSources = $proxy.GetItemDataSources($($newDataSet.Path)); }
catch{ throw $_.Exception; }
foreach ($dataSetDataSource in $dataSetDataSources)
{ #Should only be one!
$proxyNamespace = $dataSetDataSource.GetType().Namespace;
$newDataSourceReference = New-Object ($proxyNamespace.DataSource);
$newDataSourceReference.Name = $dataSetDataSource.Name;
$newDataSourceReference.Item = New-Object ($proxyNamespace.DataSourceReference);
$newDataSourceReference.Item.Reference =
$DataSourceFolder/$($xmlDataSourceReference.Query.DataSourceReference);
$dataSetDataSource.item = $newDataSourceReference.Item;
try { $proxy.SetItemDataSources($DataSetFolder/$DataSetName, $newDataSourceReference);
}
catch{ throw $_.Exception; }
}
echo "Dataset has been deployed !;
}
catch {
$valProxyError = $_.Exception.Message;
echo $_.Exception.Message;
}

You will get this message (as shown in the image below) after successful execution.


Implement Continuous Delivery for SQL Server Reporting Service Reports

After successful deployment, the data set property can be seen as shown below.


Implement Continuous Delivery for SQL Server Reporting Service Reports
Deploying Reports

Reporting Services Reports can also be deployed the in same way as the data set. First the report will be created using the CreateCatalogItem function. If there are no shared datasets used in the report, then the report needs to be re-linked with the data sources.

The SetItemDataSource function will help us to link the data source for the given report.

The script below is used to read and deploy the data set to a remote Reporting Services Server.

$ReportServerUri = "http://localhost/ReportServer_SQL2012/ReportService2010.asmx?wsdl";
$ReportFile = "C:\MSSQLTips\Tips\SSRS_Deployment_Using_ps_Part3\Reference\ScriptsAdventureWorks Sample Reports\Employee Sales Summary SQL2008R2.rdl";
$DataSourceFolder = "/MSSQLTips/Data Sources";
$DataSetFolder = "/MSSQLTips/Datasets";
$ReportsFolder = "/MSSQLTips/Reports";
$reportDataSource = "AdventureWorks2008R2";
try{
#Create Proxy
$global:proxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCredential -ErrorAction Stop;
If ($proxy -ne $null)
{
echo $global:proxy.ToString()
}
$ReportName = [System.IO.Path]::GetFileNameWithoutExtension($ReportFile)
$stream = [System.IO.File]::ReadAllBytes( $ReportFile);
$warnings =@();
try{ $newReport = $proxy.CreateCatalogItem(Report,$ReportName,$ReportsFolder,$true,$stream,$null,[ref]$warnings);
}catch{ throw $_.Exception; }
#relink report to datasource
echo Updating Datasource references;
try{ $reportDataSources = $proxy.GetItemDataSources($ReportsFolder/$ReportName); }catch{ throw $_.Exception; }
foreach ($reportDataSource in $reportDataSources)
{
$serverDataSourceItem = $allitems | where {($_.TypeName -eq DataSource) -and ($_.Path -eq
$DataSourceFolder/$($reportDataSource.Name))};
$proxyNamespace = $reportDataSource.GetType().Namespace;
$newDataSourceReference = New-Object ($proxyNamespace.DataSource);
$newDataSourceReference.Name = $reportDatasource.Name;
$newDataSourceReference.Item = New-Object ($proxyNamespace.DataSourceReference);
#$newDataSourceReference.Item.Reference = $serverDataSourceItem.Path;
$newDataSourceReference.Item.Reference = "$DataSourceFolder/$($reportDataSource.Name)";
$reportDataSource.item = $newDataSourceReference.Item;
try{ $proxy.SetItemDataSources($ReportsFolder/$ReportName, $newDataSourceReference); }catch{ throw $_.Exception; }
}
echo Report has been deployed !;
}
catch {
$valProxyError = $_.Exception.Message;
echo $_.Exception.Message;
}

You will get this message (as shown in the image below) after successful execution.


Implement Continuous Delivery for SQL Server Reporting Service Reports

After successful deployment, the dataset property can be seen as shown below


Implement Continuous Delivery for SQL Server Reporting Service Reports
Deploying the Reporting Services Data Source, Dataset and Reports in Folder A typical Business Inte

Viewing all articles
Browse latest Browse all 3160

Trending Articles