1

我有一个 SSIS 包,它根据目录中的前一天文件夹创建第二天文件夹,当我直接从 SSDT 运行包时,它会生成文件夹,但是当我将包部署到 Sql server 集成目录并执行时,我得到成功消息,但未创建文件夹。

脚本任务的变量 在此处输入图像描述

变量声明 在此处输入图像描述 在此处输入图像描述

请看下面的脚本任务代码:

   public void Main()
    {
        // TODO: Add your code here
        string DataLocation = Dts.Variables["User::FolderLocation"].Value.ToString();

        string[] Folders = Directory.GetDirectories(DataLocation);


        List<String> listFolders = new List<String>();
        List<String> listFoldersonly = new List<String>();
        List<int> lens = new List<int>();
        List<String> dates = new List<String>();
        List<DateTime> dd = new List<DateTime>();

        //get list of folders in the Directory
        if (Folders.Length > 0)
        {

            for (int x = 0; x < Folders.Length; x++)
            {

                listFolders.Add(Folders[x].ToString());
                lens.Add(Folders[x].Length);


            }
        }
        //store list of folders in an array
        string[] arrayFolders = listFolders.ToArray();
        int[] arrayLens = lens.ToArray();


        DateTime minDate = DateTime.MaxValue;
        DateTime maxDate = DateTime.MinValue;
        DateTime nextdate;

        for (int i = 0; i < arrayFolders.Length; i++)
        {
            //subtring the date from the folderlocation string
            dates.Add(arrayFolders[i].ToString().Substring(arrayLens[i] - 10));

            dd.Add(DateTime.Parse(arrayFolders[i].ToString().Substring(arrayLens[i] - 10)));

            //get the max and min date
            if (dd[i].Date < minDate)
                minDate = dd[i];
            if (dd[i] > maxDate)
                maxDate = dd[i];

        }

        nextdate = maxDate.AddDays(1);
        string nxtdate = nextdate.ToString("yyyy-MM-dd");

        String newpath = DataLocation + "\\" + nxtdate;


        Dts.Variables["User::CopyFolder"].Value = newpath.ToString();
        Dts.Variables["User::ReturnDate"].Value = nextdate.ToString();


        Directory.CreateDirectory(newpath);

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

0 回答 0