目的: SSIS パッケージにあるすべてのユーザー変数を取得し、変数名とその値を SQL Server 2008 テーブルに書き込みます。
私が試したこと:変数名とその値を表示するために機能する小さな「スクリプトタスク」を取得しました。スクリプトは次のとおりです。
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_81ec2398155247148a7dad513f3be99d.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Package pkg = app.LoadPackage(
@"C:\package.dtsx",
null);
Variables pkgVars = pkg.Variables;
foreach (Variable pkgVar in pkgVars)
{
if (pkgVar.Namespace.ToString() == "User")
{
MessageBox.Show(pkgVar.Name);
MessageBox.Show(pkgVar.Value.ToString());
}
}
Console.Read();
}
}
}
必要な作業:これを取得して、値をデータベース テーブルにダンプする必要があります。このためのスクリプト コンポーネントに取り組もうとしていますが、.net スクリプトの知識が不足しているため、ゴールに近づくことはできませんでした。これは私がコンポーネント側で行ったことです。
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts;
using System.Windows.Forms;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void CreateNewOutputRows()
{
#region Class Variables
IDTSVariables100 variables;
#endregion
variables = null;
this.VariableDispenser.GetVariables(out variables);
foreach(Variable myVar in variables)
{
MessageBox.Show(myVar.Value.ToString());
if (myVar.Namespace == "User")
{
Output0Buffer.ColumnName = myVar.Value.ToString();
}
}
}
}