I am trying to call a SSRS report via SSIS using the solution found here:https://www.mssqltips.com/sqlservertip/3475/execute-a-sql-server-reporting-services-report-from-integration-services-package/
I the script runs without error but creates a blank (4kb) Excel file. The parameters match those found in the RDL, however, ServiceArea, Location are integer values in the SQL DB. Could my issue be the data types?
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()>
<System.CLSCompliantAttribute(False)>
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub
Public Sub Main()
Dim url, destination As String
destination = Dts.Variables("Folder_Destination").Value.ToString + "" + "Report_" + Dts.Variables("Location").Value.ToString + "_" + Format(Now, "yyyyMMdd") + ".xls"
url = "https://websiteURLt&rs:Command=Render&Location=" + Dts.Variables("Location").Value.ToString + "&ServiceArea=" + Dts.Variables("ServiceArea").Value.ToString + "&StartDate=" + Dts.Variables("START_DATE").Value.ToString + "&EndDate=" + Dts.Variables("END_DATE").Value.ToString + "&DateType=" + Dts.Variables("DateType").Value.ToString + "&rs:Format=EXCEL"
SaveFile(url, destination)
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
The variables in the SSIS package are defined as STRING, Date/Time, and INT64 respectively.
5
Alan was correct – thank you!!
https://companyURL.com/ReportServer/Pages/ReportViewer.aspx%2fQuality%2fQUA_10180&rs:Command=Render&Location=90009011&ServiceArea=9000&StartDate=1/1/2024&EndDate=2/1/2024&DateType=2