Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ssis中的并行执行_Ssis - Fatal编程技术网

ssis中的并行执行

ssis中的并行执行,ssis,Ssis,我已经开发了一个主包(Main.dtsx)和3个子包(Processor.dtsx)。注意:从源位置和进程拾取文件的所有子包的代码都是相同的。为了优化性能,我希望所有这3个子包都应该在10000个文件上同时运行,这样第一个子包将选择第一个文件并开始执行,同时第二个子包将选择第二个文件,以此类推。如果有,请分享代码。我尝试使用“MaxConcurrentExecutables”选项,但在这种情况下,所有组件都访问同一个文件,这是不需要的。这不能用Foreach循环来完成,但可以用脚本任务来完成任务

我已经开发了一个主包(Main.dtsx)和3个子包(Processor.dtsx)。注意:从源位置和进程拾取文件的所有子包的代码都是相同的。为了优化性能,我希望所有这3个子包都应该在10000个文件上同时运行,这样第一个子包将选择第一个文件并开始执行,同时第二个子包将选择第二个文件,以此类推。如果有,请分享代码。我尝试使用“MaxConcurrentExecutables”选项,但在这种情况下,所有组件都访问同一个文件,这是不需要的。

这不能用Foreach循环来完成,但可以用脚本任务来完成任务:

  • 添加3个字符串变量以保存文件名(即File1、File2、File3)
  • 将变量从主包传递到每个子包
  • 在每个子包中,在文件连接管理器中配置一个表达式,以将参数用作连接字符串
  • 在每个包的末尾,确保文件从源文件夹中移动或重命名,以便在后续循环中忽略该文件
  • 设置一个For循环,该循环将在处理完所有文件后结束。您可以向包中添加一个布尔变量,如“ProcessingIsAllDone”,然后在脚本任务中进行设置
  • 在For循环的顶部,添加一个脚本任务,并将executepackage任务与先前的约束连接起来
  • 使用下面的脚本设置变量

    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Runtime;
    using System.Windows.Forms;
    using System.IO;
    
    namespace ST_e4ccd9cfaa4847ff86ec88c215c1961c
    {
        [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
        public partial class ScriptMain :     Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
        {
            public void Main()
            {
                DirectoryInfo sourceDirectory = new DirectoryInfo(@"c:\temp");
                int loops = 3;
                foreach (FileInfo sourceFile in sourceDirectory.GetFiles("*.txt"))
                {
                    if (loops == 0)
                    {
                        break;
                    }
                    string variableName = String.Format("File{0}", loops);
                    Dts.Variables[variableName].Value = sourceFile.FullName;
                    loops--;
                }
                if (sourceDirectory.GetFiles("*.txt").Length <= 3)
                {
                    Dts.Variables["ProcessingIsAllDone"].Value = true;
                }
                Dts.TaskResult = (int)ScriptResults.Success;
            }
    
        #region ScriptResults declaration
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion
    
        }
    }
    
    使用系统;
    使用系统数据;
    使用Microsoft.SqlServer.Dts.Runtime;
    使用System.Windows.Forms;
    使用System.IO;
    名称空间ST_e4ccd9cfaa4847ff86ec88c215c1961c
    {
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    公共部分类ScriptMain:Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
    公共图书馆
    {
    DirectoryInfo sourceDirectory=newdirectoryinfo(@“c:\temp”);
    int循环=3;
    foreach(sourceDirectory.GetFiles(“*.txt”)中的FileInfo sourceFile)
    {
    如果(循环==0)
    {
    打破
    }
    string variableName=string.Format(“文件{0}”,循环);
    变量[variableName].Value=sourceFile.FullName;
    循环--;
    }
    if(sourceDirectory.GetFiles(“*.txt”).Length