解決策が見つかりました。 SSISオブジェクトモデルを使用するスクリプトタスクを使用して、実行時にパッケージをファイル名でロードできるSQL Serverアプリケーションクラスに基づいてパッケージを作成することによってのみ可能です。ファイルからパッケージを読み込んだ後、xmlまたはSQL Serverによってファイルから構成を読み取り、実行時に子パッケージ構成リストに追加できます。
二つの重要な注意事項:
1)親の変数が自動的に子パッケージに渡されません。 パッケージ実行タスクが使用されている場合のみ、親変数が自動的に子に渡されます。これを実行するには、実行時に変数を検索し、変数に値を書き込んでください。各子パッケージに渡す正確な変数がわかっています。
2)SQL Serverを子パッケージのパッケージ構成として使用する場合は、実行時に接続マネージャを作成してパッケージの接続マネージャコレクションに追加する必要があります。子パッケージにパッケージ構成を追加するときは、その接続マネージャの名前が接続文字列の一部であることを確認してください。ここで
は、それが動作するか検証するためのコードです:
//load the information of the job into these variables. Package is the File system deployed package on a share. Package configuration can be the package configuration in an xml file on a share, or a connection string when using SQL Server (this one is used here).
string package = this.Dts.Variables["Package"].Value.ToString();
string packageConfiguration = this.Dts.Variables["PackageConfiguration"].Value.ToString();
//create a package from package factory, by file.
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Package packageToRun = app.LoadPackage(package, null);
//------------------------------------------ CHILD PACKAGE VARIABLES PASSING
packageToRun.EnableConfigurations = true;
//add one extra package configuration for child package specific configuration
Configuration config = packageToRun.Configurations.Add();
config.Name = "MyConfig";
config.ConfigurationType = DTSConfigurationType.SqlServer;
config.ConfigurationString = packageConfiguration;
//use the name 'MyConnectionManager' in your packageConfiguration
ConnectionManager cm = packageToRun.Connections.Add("OleDb");
cm.Name = "MyConnectionManager";
//TODO: retrieve this from an environvariable to allow change in data source for DEV, QA, PROD, now temporarly fixed to this value
cm.ConnectionString = "Data Source=.;Initial Catalog=YYYYYYYYYY;Provider=SQLNCLI10.1;Integrated Security=SSPI;";
//For Parent-Child var passing, I used the technique to let all the parent variables being defined in the child packages.
//Other technique could be to allow the child package not define the parent variables, but then the child packages have to reference them from code
//------------------------------------------ PARENT VARIABLES PASSING
//Now check if these parent variables exist in child package and write the actual values in them
try
{
Variables vars = null;
VariableDispenser variableDispenser = packageToRun.VariableDispenser;
if (
packageToRun.Variables.Contains("User::XXXXXXXXXXXX") &&
)
{
packageToRun.VariableDispenser.LockForWrite("User::XXXXXXXXXXXX");
variableDispenser.GetVariables(ref vars);
packageToRun.Variables["User::XXXXXXXXXXXX"].Value = this.Dts.Variables["User::XXXXXXXXXXXX"].Value;
vars.Unlock();
packageToRun.Execute();
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
this.Dts.Events.FireError(0, string.Empty, "Child package: " + package + " has no required master variables defined or unable to unlock.", string.Empty, 0);
}
}
catch (Exception ex)
{
this.Dts.Events.FireError(0, string.Empty, ex.Message, string.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
おかげHLGEMは、しかし、あなたはマスターパッケージによって設定をパッケージ動的にロードするための方法をいくつかの詳細を記述することができますか? –
残念ながら、それはやや難しいです:あなたがそれを記述する方法は、私にとってはうまくいかないSQL Serverによるデフォルトのパッケージ構成動作です。これは私の要求です:1つの子パッケージの場合、2つのパッケージ構成があります。マスターパッケージが、その子パッケージの実行時に、2つのパッケージ構成のいずれかにパッケージ構成を設定するようにします。 –
@Patrick Peters。同じ変数に対して異なる値を送信する2つの親パッケージを各構成ごとに1つずつ持つ必要があります。 – HLGEM