How do I copy SSRS reports to a new server if I am not the owner of the reports

后端 未结 7 1135
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 22:19

I have to copy all reports from one SSRS server to another. I plan on doing this by going through each report and downloading the report definition file and then uploading t

7条回答
  •  情歌与酒
    2020-12-08 22:49

    SSRS uses SQL Server to store it’s details as a backend and the Catalog table is used to store the report file in binary form. The below script simply pulls the report definition from the Catalog table & uses BCP utility to export the same at a pre-defined path as a .rdl file.

    To use the BCP utility from TSQL, we need to execute “xp_cmdshell” command; it is disabled by default. So, first you need to execute the below script to enable it -

    -- Allow advanced options to be changed. EXEC sp_configure 'show advanced options', 1 GO
    -- Update the currently configured value for advanced options. RECONFIGURE GO
    -- Enable xp_cmdshell EXEC sp_configure 'xp_cmdshell', 1 GO
    -- Update the currently configured value for xp_cmdshell RECONFIGURE GO
    -- Disallow further advanced options to be changed. EXEC sp_configure 'show advanced options', 0 GO
    -- Update the currently configured value for advanced options. RECONFIGURE GO

    Once successfully executed, the below script with the required changes could be executed to download the files -

    DECLARE @FilterReportPath AS VARCHAR(500) = NULL DECLARE @FilterReportName AS VARCHAR(500) = NULL

    DECLARE @OutputPath AS VARCHAR(500) = 'D:\Reports\Download\'

    DECLARE @TSQL AS NVARCHAR(MAX) SET @OutputPath = REPLACE(@OutputPath,'\','/')

    IF LTRIM(RTRIM(ISNULL(@OutputPath,''))) = '' BEGIN SELECT 'Invalid Output Path' END ELSE BEGIN SET @TSQL = STUFF((SELECT ';EXEC master..xp_cmdshell ''bcp " ' + ' SELECT ' + ' CONVERT(VARCHAR(MAX), ' + ' CASE ' + ' WHEN LEFT(C.Content,3) = 0xEFBBBF THEN STUFF(C.Content,1,3,'''''''') '+ ' ELSE C.Content '+ '
    END) ' + ' FROM ' + ' [ReportServer].[dbo].[Catalog] CL ' + ' CROSS APPLY (SELECT CONVERT(VARBINARY(MAX),CL.Content) Content) C ' + ' WHERE ' + ' CL.ItemID = ''''' + CONVERT(VARCHAR(MAX), CL.ItemID) + ''''' " queryout "' + @OutputPath + '' + CL.Name + '.rdl" ' + '-T -c -x''' FROM [ReportServer].[dbo].[Catalog] CL WHERE CL.[Type] = 2 --Report AND '/' + CL.[Path] + '/' LIKE COALESCE('%/%' + @FilterReportPath + '%/%', '/' + CL.[Path] + '/') AND CL.Name LIKE COALESCE('%' + @FilterReportName + '%', CL.Name) FOR XML PATH('')), 1,1,'')

    EXEC SP_EXECUTESQL @TSQL END

提交回复
热议问题