Search code examples
sql-serverssisssis-2008dtsscript-task

SSIS 2008 Script task compile failure: Cannot load script for execution


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 { }
    }
}

Solution

  • 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.