Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new to SSIS . I am trying to use Script Task to get the last modified date and create date of a file. I have declared two variables to read the file path and file name (File_Path,Filename) in my script task as variables with scope as package and datatype as string.

I want to store the create date and modified date to two diff output variables(Create_Date,Last_Updated) with datatype as Datetime.

my code for the script is as follows

FileInfo fileInfo = new FileInfo(Path.Combine(Dts.Variables["File_Path"].Value.ToString(), Dts.Variables["Filename"].Value.ToString()));

                if (fileInfo.Exists)
                {
                    // Get file creation date
                    Dts.Variables["Create_Date"].Value = fileInfo.CreationTime;

                    // Get last modified date
                    Dts.Variables["Last_Updated"].Value = fileInfo.LastWriteTime;

                }
                else
                {
                    
                    Dts.Events.FireWarning(1, Dts.Variables["System::TaskName"].Value.ToString()
                          , string.Format("File '{0}' does not exist", fileInfo.FullName)
                          , "", 0);
                }```

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
200 views
Welcome To Ask or Share your Answers For Others

1 Answer

SSIS has a Design time and a Run time interface.

Variables are created in the Design time space. There you assign data type and a value. There is an explicit Variable's window that you do all of this with.

During run time, the Variables window will still be visible but the values there are not the run-time value. It's just a reference for what the package was initialized with. The actual values of SSIS variables are to be found in the debug windows. I favor the Locals window (Ctrl+Alt+V, L)

Debug menu, Windows sub menu, Locals highlighted

From there, expand the Variables node

enter image description here

You can also add explicit logging into your Script tasks. This little bit will enumerate through all the variables you selected for readonly or read/write access and pop off their name and value into the run log. If you're running in Visual Studio, it will show up in the Results tab or the Output window (great place to copy errors for further research or asking on forums). If you're running from the server, these will show in the SSISDB.catalog.operation_messages view (unless you picked an incompatible logging mode)

bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
    Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...