Tony
Tony

Reputation: 55

Getting error in Script Task Editor in SSIS

I am trying to upgrade SSIS package from 2013 to 2017. But, I am getting error for the below lines of code. Can anyone please resolve this?

I am new so I haven't tried anything yet.

using System;
namespace ST_3e6cc55d375c472785d01c446ea4bf8b
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public object Now { get; private set; }

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

        };
        
        public void Main()
        {
            // TODO: Add your code here
            Dts.Variables("FileNameCSV").Value = Format(Now, "yyyyMMddHHmmss") + "_MailPieces_" + LTrim(RTrim(Dts.Variables("FrequencyType").Value)) + ".csv";
            Dts.Variables("FileNameZIP").Value = Format(Now, "yyyyMMddHHmmss") + "_MailPieces_" + LTrim(RTrim(Dts.Variables("FrequencyType").Value)) + ".zip";

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

I am getting these below errors. Please help.

Error CS1955 Non-invocable member 'ScriptObjectModel.Variables' cannot be used like a method.

Error CS0103 The name 'Format' does not exist in the current context

Error CS0103 The name 'LTrim' does not exist in the current context

Error CS0103 The name 'RTrim' does not exist in the current context

Upvotes: 0

Views: 2806

Answers (2)

Hadi
Hadi

Reputation: 37313

Three suggestions:

  1. Replace Now with DateTime.Now
  2. Use ToString(<format>) instead of Format()
  3. Use Trim() instead of LTrim(RTrim())

Try using the following code:

using System;
namespace ST_3e6cc55d375c472785d01c446ea4bf8b
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {


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

        };

        public void Main()
        {
            // TODO: Add your code here
            Dts.Variables("FileNameCSV").Value = DateTime.Now.ToString("yyyyMMddHHmmss") + "_MailPieces_" + Dts.Variables("FrequencyType").Value.ToString().Trim() + ".csv";
            Dts.Variables("FileNameZIP").Value = DateTime.Now.ToString("yyyyMMddHHmmss") + "_MailPieces_" + Dts.Variables("FrequencyType").Value.ToString().Trim() + ".zip";

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

Upvotes: 1

digital.aaron
digital.aaron

Reputation: 5707

Looks like you're missing the reference to DTS runtime assembly. Try adding this to your using block:

using Microsoft.SqlServer.Dts.Runtime; 

Upvotes: 0

Related Questions