SSIS脚本任务(计划时不工作)

时间:2017-12-12 00:06:46

标签: sql-server ssis etl

我有一个带有脚本任务的SSIS包。该任务在Visual Studio 2015中运行良好。但是,当我部署程序包并通过SSMS运行它时,任务脚本显示成功,但它运行速度非常快,并且不会创建该文件。我的代码非常简单(从网址抓取文件,并将其保存到网络位置)

Public Sub Main()
    Dim url, destination As String
    destination = Dts.Variables("StagingPath").Value.ToString + Dts.Variables("DeliveryFile").Value.ToString
    url = Dts.Variables("ReportURL").Value.ToString

    'Delete staging file if it exists
    Try
        If IO.File.Exists(destination) Then IO.File.Delete(destination)

        Dim result As Boolean = SaveFile(url, destination)
        If result = True Then
            Dts.TaskResult = ScriptResults.Success
        Else
            Dts.TaskResult = ScriptResults.Failure
        End If

    Catch ex As Exception
        Dts.TaskResult = ScriptResults.Failure
    End Try
End Sub

Protected Function SaveFile(ByVal url As String, ByVal localpath As String) As Boolean
    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()

        'Success
        SaveFile = True

    Catch ex As Exception
        SaveFile = False
    End Try
End Function

就像我说的,在本地运行时一切正常,但在部署到SSISDB目录时却没有。传递的URL是我们的SSRS服务器上的本地资源,即pdf文件。

1 个答案:

答案 0 :(得分:0)

解决方案是每当我更改脚本任务时部署整个项目,或者脚本任务甚至不会尝试运行,而是报告成功运行。