Tuesday 22 December 2015

EncryptionKeys Backup and Restore




Encryption Keys:
    Reporting Services uses encryption keys to secure credentials and connection information that is stored in a report server database. In Reporting Services, encryption is supported through a combination of public, private, and symmetric keys that are used to protect sensitive data.

Encryption Keys Backup:
  • Open the "Reporting Services Configuration Manager"


  • Give the Server name and click on "Connect" button.
  • Go to "Encryption Keys" section and click on "Backup" button (highlighted in the below screenshot).
  • Then "Encryption Key Information" will open. Give the "Password" (any name we can give) and "Key file" path. After that click on "OK" button. It will create backup file in the given location.



Restoring:

  • Open the "Reporting Services Configuration Manager".


  • Give the Server name and click on "Connect" button.
  • Go to "Encryption Keys" section and click on "Restore" button (Highlighted in the above screenshot).
  • Specify the backup file and give the required password. Then click on "OK" button.

Saturday 12 December 2015

Upload Multiple RDL Files from Local path to ReportServer (Using RS.exe Utility)



      This article explains how to Upload/Deploy the multiple RDL files from local machine to ReportManager. We can Upload/Deploy multiple RDL files at a time using RS.exe utility. RS.exe utility is a command line utility that can perform many scripted operation related to SQL Server Reporting Services (SSRS).

Note: Rs.exe file path will change based on the SQL Server/SSRS version

EXE file is located any one of the below locations (Based on SQL Server/SSRS Version):
For 64 Bit: \Program Files\Microsoft SQL Server\100\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\100\Tools\Binn
OR
For 64 Bit: \Program Files\Microsoft SQL Server\110\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\110\Tools\Binn
OR
For 64 Bit: \Program Files\Microsoft SQL Server\120\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\120\Tools\Binn

For this process we need to prepare three files
  1. Script File (For uploading all RDL Files)
  2. Configuration file (We need to specify the "Local folder path and ReportManager folder path")
  3. Batch file (To execute the RS.exe based on script present in the script file)

1. Script to prepare ScriptFile (Copy the below script and past it in text file and save with the name and extension as “Upload_Multiple_RDL_files.rss”):

'Script Starting Point
' Script to deploy report to report server
' EXECUTE VIA COMMAND LINE

DIM definition As [Byte]() = Nothing
DIM warnings As Warning() = Nothing

Public Sub Main()

' Variable Declaration
        Dim TextLine As String = ""
        Dim LocalDir As String = ""
        Dim ServerDir As String = ""
        Dim definition As [Byte]() = Nothing
        'Dim warnings As Warning() = Nothing

' Reading Configuration Text file and assigning the values to variables
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
                TextLine = objReader.ReadLine()
                Dim parts As String() = TextLine.Split(New Char() {","c})
                'TextLine & objReader.ReadLine() '& vbNewLine
                LocalDir = parts(0)
                ServerDir = parts(1)

                Dim path As String = LocalDir
                Dim fileEntries As String() = Directory.GetFiles(path)
                Dim fileFullPath As String = ""
                For Each fileFullPath In fileEntries


 ' Deploying the Reports
                    Try
                        Dim stream As FileStream = File.OpenRead(fileFullPath)
                        Dim NameWithExt As String = fileFullPath.Replace(path, "")
                        Dim NameOnly As String = NameWithExt.Replace(".rdl", "")
                        definition = New [Byte](stream.Length) {}
                        stream.Read(definition, 0, CInt(stream.Length))

warnings = rs.CreateReport(NameOnly, ServerDir, True, definition, Nothing)

If Not (warnings Is Nothing) Then
DIM warning As Warning
For Each warning In warnings
Console.WriteLine(warning.Message)
Next warning
Else
Console.WriteLine("Report: {0} PUBLISHED!", NameOnly)
End If

Catch e As IOException
Console.WriteLine(e.Message)
End Try
Next fileFullPath
Loop
         Else

            Dim MsgBox as String = "File Does Not Exist"

        End If
End Sub

'End of the Script



2. Configuration file: In this file we need to specify the source folder path (where the RDL files are located) and Target (ReportServer path, to where we need to upload the RDL files) with comma separate. Please refer the below attached images.

In this example, i have RDL files in two different folders and i want to upload them into different target folders in the report server.

Local Machine Path:
C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\SSRS\SalesReports\
C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\SSRS\Aggregate\

Report Server Path:
/SSRS/SalesReports
/SSRS/Aggregate






3. Command to prepare BatchFile (Copy the below command and past it in text file and save with the name and extension as “UploadRDLFiles.bat”):
Note: Verify the rs.exe file path in your Machine and Update the below path if the file is present in different location.

"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\rs.exe" -i C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\Upload_Multiple_RDL_files.rss -s "http://admin-pc:8080/ReportServer" -v FILE_NAME="C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\ConfigurationFile.txt"

Pause




After preparing the three files (Script File, Configuration file and Batch File), edit the batch file and update the "Rs.exe file path, .RSS script file path, ReportServer URL,  and Configuration file path".
  • Rs.exe file path: Update with the Rs.exe file path (file is located at \Program Files\Microsoft SQL Server\110\Tools\Binn)

  • .RSS script file path: Update with the .rss script file path (where we placed the ScriptFile "Upload_Multiple_RDL_files.rssfile).

  • ReportServer URL: Update with the required ReportServer URL (To where we need to upload the RDL files).

  • Configuration file path: Update the file with required source and targets paths.

Sample Screenshot of the files:

After Updating the Script and Batch files, double click on the batch file then execution will start.

Note: We are uploading/Deploying only RDL files, so we may receive the below message. We can ignore that.

Message:

The dataset “<<Dataset name>>” refers to the shared data source “<<Dataset name>>”, which is not published on the report server. The shared data source “<<Dataset name>>” must be published before this report can run.

Note: If the Reports are referring to share data sources those may not work, if so edit RDL files Data source from report manager and updated with appropriate Data source.

See Also:
Download the all RDL files from ReportManager (Using RS.exe Utility)

Download the all RDL files from ReportManager (Using RS.exe Utility)



      This article explains how to download the all RDL files from ReportManager. We can download all the RDL files at a time using RS.exe utility. RS.exe utility is a command line utility that can perform many scripted operation related to SQL Server Reporting Services (SSRS).

Note: Rs.exe file path will change based on the SQL Server/SSRS version

EXE file is located any one of the below locations (Based on SQL Server/SSRS Version):
For 64 Bit: \Program Files\Microsoft SQL Server\100\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\100\Tools\Binn
OR
For 64 Bit: \Program Files\Microsoft SQL Server\110\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\110\Tools\Binn
OR
For 64 Bit: \Program Files\Microsoft SQL Server\120\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\120\Tools\Binn


For this process we need to prepare two files
  1. Script File (For downloading all RDL Files)
  2. Batch file (To execute the RS.exe based on script present in the script file)

1. Script to prepare ScriptFile (Copy the below script and past it in text file and save with the name and extension as “Download_all_RDL_files.rss”):

'Script Starting Point
'This script downloads the all RDL files from ReportServer

Sub Main()
    Dim items As CatalogItem() = _
        rs.ListChildren("/", true)

    For Each item As CatalogItem in items
        If item.Type = ItemTypeEnum.Folder Then
            CreateDirectory(item.Path)
        Else If item.Type = ItemTypeEnum.Report Then
            SaveReport(item.Path)
        End If
    Next
End Sub

Sub CreateDirectory(path As String)
    path = GetLocalPath(path)
    System.IO.Directory.CreateDirectory(path)
End Sub

Sub SaveReport(reportName As String)
    Dim reportDefinition As Byte()
    Dim document As New System.Xml.XmlDocument()

    reportDefinition = rs.GetReportDefinition(reportName)
    Dim stream As New MemoryStream(reportDefinition)

    document.Load(stream)
    document.Save(GetLocalPath(reportName) + ".rdl")
End Sub

Function GetLocalPath(rsPath As String) As String
    Return rootPath + rsPath.Replace("/", "\")
End Function

'End of the Script



2. Command to prepare BatchFile (Copy the below command and past it in text file and save with the name and extension as “DownloadRdlFiles.bat”):

Note: Verify the rs.exe file path in your Machine and Update the below path if the file is present in different location.

"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\rs.exe" -s "http://admin-pc:8080/ReportServer" -i C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Download_rdl_files\Download_all_RDL_files.rss -v rootPath="C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Download_rdl_files\RDL_files\\"
Pause


After preparing two files (Script File and Batch File), edit the batch file and update the "Rs.exe file path, ReportServer URL, .RSS script file path and RootPath (Local path, where we need to keep the RDL files)".
  • Rs.exe file path: Update with the Rs.exe file path (file is located at \Program Files\Microsoft SQL Server\110\Tools\Binn)

  • ReportServer URL: Update with the required ReportServer URL (From where we need to download RDL files)

  • .RSS script file path: Update with the .rss script file path (where we placed the ScriptFile "Download_all_RDL_files.rss" file).

  • RootPath: Update with the required path (where we need to place the downloaded RDL files)

Sample Folder Structure:

After Updating the Script and Batch files, double click on the batch file then execution will start.

Also:
Upload Multiple RDL Files from Local path to ReportServer (Using Rs.Exe Utility)