SSIS脚本任务错误检索变量值

时间:2010-02-02 22:38:53

标签: ssis

Script Task中,我正在尝试从联网位置检索文件,并将FTP该文件检索到非现场位置

  • 在SSIS中,我创建了FTP Connection并测试了它是否已设置并正常工作
  • 创建了三个变量

    • 变量1. FullPathName = \ ftpservercsc \\\ Filename.txt
    • 变量2 FTPFilePath = \ ftpservercsc \\\
    • 变量3 FTPFileName = Filename.txt
  • 创建了Script Task并添加了vb代码......

    'Get instance of the connection manager.
    Dim cm As ConnectionManager = Dts.Connections("FTP Connection Manager")
    Dim remotePath As String = Dts.Variables("FTPFilePath").Value.ToString
    
    'create the FTP object that sends the files and pass it the connection
    'created above.
    Dim ftp As FtpClientConnection = New FtpClientConnection
                                            (cm.AcquireConnection(Nothing))
    
    'Connect to the ftp server
    ftp.Connect()
    
    'Set the path on the FTP server where dropping files
    'ftp.SetWorkingDirectory("/Prequalify") 'set the remote directory
    
    Dim files(0) As String
    files(0) = Dts.Variables("FTPFileName").Value.ToString 'eg. File1.trg
    
    'Send File
    ftp.SendFiles(files, remotePath, True, True)
    
    ' Close the ftp connection
    ftp.Close()
    
    
    'Dts.Events.FireInformation(0, context, "File " + fileToGet 
    '     + " retrieved successfully.", Nothing, Nothing, True)
    Dts.TaskResult = Dts.Results.Success
    
  • 错误:在集合中找不到该元素。当您尝试在执行包期间从容器上的集合中检索元素并且该元素不存在时,会发生此错误。

所以我已经注释掉了,发现错误是在检索变量值时产生的,但我不知道这里有什么不正确

    Dim remotePath As String = Dts.Variables("FTPFilePath").Value.ToString

我尝试了多个变量检索,但都得到了同样的错误。有人看错了吗?

1 个答案:

答案 0 :(得分:15)

两件事:

  1. 确保将脚本任务配置为对变量具有读取权限。要执行此操作,请右键单击“脚本任务”,然后选择“编辑”。单击ReadOnlyVariables下的....
  2. 完全限定您的变量,例如Dts.Variables["User::RemotePath"].Value