I was working on some SSRS reports which I’ve to deploy on
the report server in the various test and production environments.
So it was decided to automate this process of deploying all
reports in one go rather than manually deploying each report one by one.
So here’s how the deployment script was created:
1)
Create a folder on your Report Server where you
needs to drop your report files:
“C:\ReportsToPublish\”
2)
Now there is a file which comes with SQL Server
samples whose extension is “.rss” which actually contains some VB code which
will go through each report in your ReportsToPublish folder and then deploy
them one by one. I’ve placed this .rss file in same ReportsToPublish folder.
“C:\ReportsToPublish\PublishReports.rss”
3)
Now we have to edit the PublishReports.rss file.
Here we’ll provide the connection string for the Reports Data source, the
reports to be published, and the folder on report server in which reports will
be published i.e. parent folder and setting the data source to each report. The
code below that we need to edit in the PublishReports.rss:
Dim definition As [Byte]() = Nothing
Dim warnings As Warning() = Nothing
Dim parentFolder As String = "<parent
folder name>"
Dim parentPath As String =
"/" + parentFolder
Dim filePath As String =
"C:\ReportsToPublish\Reports\"
Dim dataSourcePath As String =
"/Data Sources"
Public Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
'Create the parent folder
Try
rs.CreateFolder(parentFolder, "/", Nothing)
Console.WriteLine("Parent folder {0} created successfully",
parentFolder)
Catch e As SoapException
Console.WriteLine(e.Detail("Message").InnerXml)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
'Create the Reports shared data source
CreateDataSource("<datasource name>", "SQL",
"data source=(local);initial catalog=<database name>")
'Publish the sample reports
PublishReport("<your report name>")
'Set data source for the reports
SetReportDataSource("<your report name>")
End Sub
4)
Now create a batch file which will use the
PublishReport.rss file to deploy the reports on report server. The code for the
batch file will be:
echo 'Publishing reports on the report
server'
rs -i
"C:\ReportsToPublish\PublishReports.rss" -s
"http://localhost/reportserver"
Cheers
Ankit
No comments:
Post a Comment