Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

SSIS value of variable not changing

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);
                }```
question from:https://stackoverflow.com/questions/65670925/ssis-value-of-variable-not-changing

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

1 Reply

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...