I am working on creating a stored procedure that exports a pdf report from a SSRS report server. The report needs a parameter called “ExportId”. The procedure runs successfully but it does not create a pdf. What am I doing wrong here?
<code>
Alter PROCEDURE rsp_GenerateAndDeliverReports
@ReportName NVARCHAR(100),
@Parameter1Name NVARCHAR(100),
@Parameter1Value NVARCHAR(100),
@OutputFile NVARCHAR(100)
AS
BEGIN
-- Variables
DECLARE @executionID AS INT
DECLARE @reportBytes AS VARBINARY(MAX)
DECLARE @zipFilePath AS NVARCHAR(100)
DECLARE @reportService AS INT -- Change the data type to INT
-- Create an instance of the SSRS Execution Service
EXEC sp_OACreate 'SSRS.ReportExecutionService', @reportService OUT
-- Initialize the service
EXEC sp_OASetProperty @reportService, 'Url', 'http://localhost/ReportServer/ReportExecution2005.asmx'
-- Load Report 1
EXEC sp_OAMethod @reportService, 'LoadReport', NULL, @ReportName, NULL, @executionID OUT
-- Set Report 1 Parameters
EXEC sp_OAMethod @reportService, 'SetExecutionParameters', NULL, @Parameter1Name, @Parameter1Value
-- Render Report 1
EXEC sp_OAMethod @reportService, 'Render', @reportBytes OUTPUT, 'PDF', NULL, NULL, NULL, NULL, NULL
-- Close and release the service
EXEC sp_OADestroy @reportService
-- Save Report 1 as PDF
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'DECLARE @file AS VARBINARY(MAX)
SET @file = ' + CONVERT(NVARCHAR(MAX), @reportBytes, 1) + '
EXEC sp_writebytesfile @file, ''' + @OutputFile + ''
EXEC sp_executesql @sql
END
EXEC rsp_GenerateAndDeliverReports @ReportName='/All Reports/Subreports/07_sub', @Parameter1Name ='ExportId', @Parameter1Value='2', @OutputFile='C:UsersPublicPublic DownloadsReport.pdf'
</code>
<code>
Alter PROCEDURE rsp_GenerateAndDeliverReports
@ReportName NVARCHAR(100),
@Parameter1Name NVARCHAR(100),
@Parameter1Value NVARCHAR(100),
@OutputFile NVARCHAR(100)
AS
BEGIN
-- Variables
DECLARE @executionID AS INT
DECLARE @reportBytes AS VARBINARY(MAX)
DECLARE @zipFilePath AS NVARCHAR(100)
DECLARE @reportService AS INT -- Change the data type to INT
-- Create an instance of the SSRS Execution Service
EXEC sp_OACreate 'SSRS.ReportExecutionService', @reportService OUT
-- Initialize the service
EXEC sp_OASetProperty @reportService, 'Url', 'http://localhost/ReportServer/ReportExecution2005.asmx'
-- Load Report 1
EXEC sp_OAMethod @reportService, 'LoadReport', NULL, @ReportName, NULL, @executionID OUT
-- Set Report 1 Parameters
EXEC sp_OAMethod @reportService, 'SetExecutionParameters', NULL, @Parameter1Name, @Parameter1Value
-- Render Report 1
EXEC sp_OAMethod @reportService, 'Render', @reportBytes OUTPUT, 'PDF', NULL, NULL, NULL, NULL, NULL
-- Close and release the service
EXEC sp_OADestroy @reportService
-- Save Report 1 as PDF
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'DECLARE @file AS VARBINARY(MAX)
SET @file = ' + CONVERT(NVARCHAR(MAX), @reportBytes, 1) + '
EXEC sp_writebytesfile @file, ''' + @OutputFile + ''
EXEC sp_executesql @sql
END
EXEC rsp_GenerateAndDeliverReports @ReportName='/All Reports/Subreports/07_sub', @Parameter1Name ='ExportId', @Parameter1Value='2', @OutputFile='C:UsersPublicPublic DownloadsReport.pdf'
</code>
Alter PROCEDURE rsp_GenerateAndDeliverReports
@ReportName NVARCHAR(100),
@Parameter1Name NVARCHAR(100),
@Parameter1Value NVARCHAR(100),
@OutputFile NVARCHAR(100)
AS
BEGIN
-- Variables
DECLARE @executionID AS INT
DECLARE @reportBytes AS VARBINARY(MAX)
DECLARE @zipFilePath AS NVARCHAR(100)
DECLARE @reportService AS INT -- Change the data type to INT
-- Create an instance of the SSRS Execution Service
EXEC sp_OACreate 'SSRS.ReportExecutionService', @reportService OUT
-- Initialize the service
EXEC sp_OASetProperty @reportService, 'Url', 'http://localhost/ReportServer/ReportExecution2005.asmx'
-- Load Report 1
EXEC sp_OAMethod @reportService, 'LoadReport', NULL, @ReportName, NULL, @executionID OUT
-- Set Report 1 Parameters
EXEC sp_OAMethod @reportService, 'SetExecutionParameters', NULL, @Parameter1Name, @Parameter1Value
-- Render Report 1
EXEC sp_OAMethod @reportService, 'Render', @reportBytes OUTPUT, 'PDF', NULL, NULL, NULL, NULL, NULL
-- Close and release the service
EXEC sp_OADestroy @reportService
-- Save Report 1 as PDF
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'DECLARE @file AS VARBINARY(MAX)
SET @file = ' + CONVERT(NVARCHAR(MAX), @reportBytes, 1) + '
EXEC sp_writebytesfile @file, ''' + @OutputFile + ''
EXEC sp_executesql @sql
END
EXEC rsp_GenerateAndDeliverReports @ReportName='/All Reports/Subreports/07_sub', @Parameter1Name ='ExportId', @Parameter1Value='2', @OutputFile='C:UsersPublicPublic DownloadsReport.pdf'