Search code examples
sql-server-2008visual-studio-2008ssisssis-2008

How to use parameter to set the path for script task SSIS


I need to set the directory path in the script task component in SSIS package.

I am using Visual Studio 2008 to build the SSIS package inside that I have one action where in i need to create the folder hierarchy.

Instead of hard coding I need to set with parameter so that when they run the package they can change the folder path.

where I can set the parameter to perform dynamic action.

string _FileDirectory = @"C:/EPLInterface/PPSExtractor/";

Also how to access the created parameter in visual studio 2008 to build the package.


Solution

  • Create a variable in the control Flow like below

    enter image description here

    once you create variable open the script editor and add the variable u created some thing like below

    note* : Variable what you have created will automatically appear here.

    enter image description here

    Then Click on Edit Script and access the variable as below:

    if (Dts.Variables["User::FilePath"].Value !=null && !string.IsNullOrEmpty(Dts.Variables["User::FilePath"].Value.ToString()))
                    {
                        _FileDirectory = Dts.Variables["User::FilePath"].Value.ToString() + "\\";
                    }
    

    If you want to change this path Dynamically you can do it something like below:

    dtexec /FILE "C:\Users\kata\Desktop\ExtractData.dtsx" /Set \Package.Variables[User::FilePath].Properties[Value];"C:\Newpath"
    

    Also you can change when u run the SSIS package as below:

    enter image description here