0

I'm running SSIS 2008, and I'm getting 'Cannot load script for execution.' error when running the script below. I'm able to build this script when editing script task, but it crashes when I run a package. I've tried multiple variations of this script, for example, instead of declaring c# variable dtss below, I've used DTS.Variables default object, it gave me the same issue. Please note I'm not .NET expert, but I need to create folder programmatically only if it doesn't exist, so I need to use script component. As I can see, it's a very "popular" issue, so I've tried some solutions suggested on this forum, but nothing worked for me.

using System;
using System.IO;
using System.Data;
using Microsoft.SqlServer.Dts;
using Microsoft.SqlServer.Dts.Runtime;



class Test
{
    /*protected static Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel CurrDtsContext;*/
    protected static Microsoft.SqlServer.Dts.Runtime.Variables dtss;
    public static void Main()
    {

        // Specify the directory you want to manipulate.
        string path = (string)(dtss["ArchivePath"].Value + "\\" + dtss["FacilityName"]);

        try
        {
            // Determine whether the directory exists.
            if  (!Directory.Exists(path))
            {
                // Try to create the directory.
                DirectoryInfo di = Directory.CreateDirectory(path);
            }

        }
        catch (Exception e)
        {
            Console.WriteLine("The process failed: ", e.ToString());
        }
        finally { }
    }
}
Leo Dan
  • 23
  • 6
  • You don't need to use a script task for this. You can just use a one liner in an execute process task. https://stackoverflow.com/questions/4165387/create-folder-with-batch-but-only-if-it-doesnt-already-exist . If you insist on using a script, you have to do weird things like giving access to Windows\temp https://blogs.msdn.microsoft.com/mab/2008/11/06/custom-security-and-sql-job-with-ssis-script-task/ – Nick.Mc Mar 14 '18 at 22:39
  • Thank you, I've eventually used File System task with property UseDirectoryIfExist=TRUE, this way it doesn't overwrite existing folder and doesn't seem to throw any error if folder already exist. – Leo Dan Mar 15 '18 at 20:09

1 Answers1

0

I've eventually used File System task with property UseDirectoryIfExist=TRUE, this way it doesn't overwrite existing folder and doesn't seem to throw any error if folder already exist.

Leo Dan
  • 23
  • 6