开发者

Passing variable from batch file to SSIS package

I have created a package which takes a variable from batch file and uses it for execution.

I am sending it from batch file as:

Exit %Output%

And set Output of Execute pro开发者_StackOverflow中文版cessTask but not being able to access it further.

Please help.!


I think that you should echo the variable %Output% instead of using with Exit command.

Following example shows how to pass a string from batch file to SSIS:

  1. Screenshot #1 shows the contents of the batch file used in this example.
  2. Screenshot #2 shows the Execute Process Task configuration. The variable BatchOutput is of type string.
  3. Screenshot #3 shows that the Script Task Success is added after the batch Execute Process Task.
  4. In the Script Task, I have the code shown under the Script Task code section to display the contents of the variable BatchOutput.
  5. Execution of the task should show the contents of the variable, which is actually the text echoed from the batch file. refer screenshot #4.

Script Task code: (Use the code given below to replace the Main() method in your Script task)

VB Main() method code that can be used in SSIS 2005 and above

Public Sub Main()
    Dim varCollection As Variables = Nothing    

    Dts.VariableDispenser.LockForRead("User::BatchOutput")
    Dts.VariableDispenser.GetVariables(varCollection)

    MessageBox.Show(varCollection("User::BatchOutput").Value.ToString())

    Dts.TaskResult = ScriptResults.Success
End Sub

C# Main() method code that can be used only in SSIS 2008 and above .

public void Main()
{
    Variables varCollection = null;
    Dts.VariableDispenser.LockForRead("User::BatchOutput");
    Dts.VariableDispenser.GetVariables(ref varCollection);

    MessageBox.Show(varCollection["User::BatchOutput"].Value.ToString());
    Dts.TaskResult = (int)ScriptResults.Success;
}

Hope that helps.

Screenshot #1:

Passing variable from batch file to SSIS package

Screenshot #2:

Passing variable from batch file to SSIS package

Screenshot #3:

Passing variable from batch file to SSIS package

Screenshot #4:

Passing variable from batch file to SSIS package

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜