我想使用SSIS导出PDF文件。要导出的报告有一个参数(type = integer)。我在互联网上发现的代码完全是这样做的here。SSIS创建0 KB PDF文件
但是,当我从ssis运行此代码时,它会导出pdf,但文件大小为0KB。试图打开PDF文件时出现错误。
下面是我使用的代码:我试图去URL http://Server/ReportServer/Pages/ReportViewer.aspx?%2fMapName%2fMapName%2fMapName%2Repportname&Parameter=“parametersqlresults”格式
Imports System
Imports System.Data
Imports System.Net
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<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 myCredentials As New NetworkCredential("username", "password")
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 = myCredentials
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("varDestinationPath").Value.ToString + "\" + Dts.Variables("varRSParameter").Value.ToString + " " + Format(Now, "yyyyMMdd") + ".pdf"
url = "http://Server/ReportServer/Pages/ReportViewer.aspx?%2fMap%2fMap%2fMap%2Repportname&Parameter=" + Dts.Variables("varRSParameter").Value.ToString + "&rs:Format=PDF"
SaveFile(url, destination)
Dts.TaskResult = ScriptResults.Success
End Sub
当我这样做,我得到一个下载PDF和一切行得通。
我认为有可能是一些与连接到报告服务器,所以我说这代码:
`Imports System.Net
Dim myCredentials As New NetworkCredential("username", "password")
loRequest.Credentials = myCredentials`
另外在Windows日志报告服务器上>安全 我可以看到审核成功用提供的用户名和密码。
我将位置改为将pdf保存到多个位置。我也改变了从数据类型“字符串”变量的数据类型为“INT32” 没有成功
对于你说的工作,如果你手动去它并不意味着是代码的URL格式相同的URL。这是一个错字吗? – DForck42
我不能看到错字?但在我的VBScript中,当我按住CTRL时,它会要求输入凭证,并且在填写完参数后我可以看到该报告。 – Vico