2016-11-10 5 views
1

Ich habe ein SSIS-Paket mit einer Skriptaufgabe, um den Namen und den Speicherort einer Datei festzulegen. Ich habe kürzlich versucht, es zu aktualisieren, um eine inkrementierende Zahl am Ende des Dateinamens hinzuzufügen. Wenn ich es laufen, ich eine Fehlermeldung erhalten:SSIS-Skriptaufgabe kann Variable nicht finden

Error: 0xC0014054 at Script Task: Failed to lock variable "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException: The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there. 
---> System.Runtime.InteropServices.COMException (0xC0010009): The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there. 

Es danach viel mehr ist, aber das ist das Wesentliche.

Die Sache ist, es findet alle Variablen früher im selben Code, und da es nicht sagt, welche Variable es nicht finden kann, weiß ich nicht, was das Problem ist. Ich konnte die Linie aufzuspüren es vor sich versagt, obwohl mein Code hier:

Public Sub Main() 
    Dim sFile As String 
    Dim i As Integer 
    Dim bExists As Boolean 

    i = 1 
    bExists = True 

    Dts.Variables("User::UStartTime").Value = Dts.Variables("System::StartTime").Value 
    Dts.Variables("User::FileName").Value = Dts.Variables("User::Protocol").Value.ToString _ 
              & "_" & CStr(Format(Dts.Variables("User::UStartTime").Value, "yyyyMMdd")) _ 
              & "_" & CStr(i) 

    Dts.Variables("User::FileLocation").Value = "\\ACMSHARES2\clntrial\DataMgt\" _ 
               & Dts.Variables("User::StudyNumber").Value.ToString _ 
               & "\" + Dts.Variables("User::FileLocation").Value.ToString _ 
               & Dts.Variables("User::FileName").Value.ToString _ 
               & "." & Dts.Variables("User::FileType").Value.ToString 

    'Add incrementing number to end of file name per DMA 
    Do Until bExists = False 
     'SCRIPTING TASK FAILS ON THE NEXT LINE 
     sFile = Dts.Variables("User::Filelocation").Value 

     If File.Exists(sFile) Then 
      i = i + 1 
      Dts.Variables("User::FileName").Value = Dts.Variables("User::Protocol").Value.ToString _ 
              & "_" & CStr(Format(Dts.Variables("User::UStartTime").Value, "yyyyMMdd")) _ 
              & "_" & CStr(i) 
      Dts.Variables("User::FileLocation").Value = "\\ACMSHARES2\clntrial\DataMgt\" _ 
               & Dts.Variables("User::StudyNumber").Value.ToString _ 
               & "\" + Dts.Variables("User::FileLocation").Value.ToString _ 
               & Dts.Variables("User::FileName").Value.ToString _ 
               & "." & Dts.Variables("User::FileType").Value.ToString 
     Else 
      bExists = False 
     End If 
     MsgBox("Loop iterated") 
    Loop 

    Dts.TaskResult = ScriptResults.Success 
End Sub 

So scheitert es, wenn sie die Linie erreicht sFile = Dts.Variables("User::Filelocation").Value

Irgendwelche Ideen?

+0

Es gibt kein VBScript in Ihrer Frage. –

+0

Ja, es ist VB.Net Ich entfernte die Tags aus dem Titel und legte sie als Tags – Shiva

Antwort

3

Während VB Groß-und Kleinschreibung nicht beachtet, sind SSIS-Variablen Groß-und Kleinschreibung. Sie haben einen Kleinbuchstaben L in FileLocation verwendet

sFile = Dts.Variables("User::FileLocation").Value 
+0

Ja. Ja, habe ich. Oh! – JeffK627

Verwandte Themen