2016-11-10 13 views
1

SSISパッケージには、ファイルの名前と場所を設定するスクリプトタスクがあります。私は最近、ファイル名の最後にインクリメントする番号を追加するように更新しようとしました。SSISスクリプトタスクで変数が見つかりません

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. 

は、その後多くのありますが、これは要旨次のとおりです。私はそれを実行すると、私はエラーメッセージが表示されます。事がある

が、それは同じコードで、以前のすべての変数を見つけ、それはそれを見つけることができない変数言っていないので、私は、問題が何であるかを知りません。

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 

だから、それがラインsFile = Dts.Variables("User::Filelocation").Value

任意のアイデアに到達したときに失敗します。私はここに私のコードですけれども、それは上の失敗だラインを追跡することができましたか?

+0

あなたの質問にはvbscriptはありません。 –

+0

うんVB.Netですタイトルからタグを削除してタグとして入れました – Shiva

答えて

3

VBは大文字と小文字が区別され大文字と小文字を区別しない、SSIS変数されています。 FileLocationで小文字のLを使用しました

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

はい。はい、私はしました。 D'oh! – JeffK627

関連する問題