Ssis Script Task Storing Datetime in Variable

Ssis Script Task Storing Datetime in Variable

I'm not sure why this happens, but my script task is not storing a DateTime-Value in a variable. This is the (till now) very basic code I've written:

[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
    public void Main()
    {
        DateTime creationTime;
        DateTime modifiedTime;
        DateTime oldCreationDate = (DateTime)Dts.Variables["User::OldFileDate"].Value;
        DateTime oldModifiedTime = (DateTime)Dts.Variables["User::OldModifiedDate"].Value;

        Dts.Variables["User::OldFileDate"].Value = DateTime.Now;

        Dts.TaskResult = (int)ScriptResults.Success;
    }

    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
}

It's not done yet, but I wanted to check if the variable is stored or not. I checked the variables using the debugger, during runtime the varible changes, but if I look at the variable after the execution it is still the same value. I also checked the properties and ReadOnly is False and the Variables are also added to the package. Any Ideas on what I am doing wrong?

11

1 Answer

Once stopped at a breakpoint, look at your variables in the watch window for run time values. The variable window is not updated during debugging.

EDIT: Based on your comment ignore the above. You can save the variable at any time in your package including the end. I suggest that you use an execute SQL task to:

Insert Into ImportedFiles (FileName, Imported) Values (?, getdate())

Based on comments to your question you want to determine if the file was imported previously. You can do:

Select 1 From ImportedFiles Where FileName = ?

Then based on that query you can set up logic to either import the file or skip it.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.