简体   繁体   中英

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. 变数 sis中的变量声明 Any Ideas on what I am doing wrong?

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.

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