简体   繁体   中英

SSIS: Add Creation Date to Variable in Script Task

I am trying to obtain the creation date of a file in SSIS using a script task. I have created a variable named "User::File_Created" and added that variable to the following script task:

        public void Main()
        {
            string fileName = @"[FilePath]";
            FileInfo fi = new FileInfo(fileName);

            if (Dts.Variables.Contains("User::File_Created") == true)
            {
                Dts.Variables["User::File_Created"].Value = fi.CreationTime;
            }
        }

Upon completion though, I still only see the current date stored in the variable. Any help would be appreciated.

This is a common point of confusion.

The Variables window is where you create SSIS variables and assign design-time values. Design time values are just that, design only. The package will initialize with those values but they can change during execution. When the package terminates, it does not save the current value back to the package because that was all run-time. Design time remains constant.

在此处输入图像描述

To see the run-time values, you need to pull up the Locals window, expand the Variables collection node and then you can see all the current values (or set a watch for it). Here you can see my package is in flight as we have green nodes (expression task that set the value of my variable to ZYX) and the Variables window shows ABC but the Locals window reflects the true value of ZYX

在此处输入图像描述

To access the Locals window, while the package is debugging, click the Debug menu, under Windows, select Locals. https://learn.microsoft.com/en-us/visualstudio/debugger/autos-and-locals-windows?view=vs-2019

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM