3

I've created a custom class in one of my flow tasks and assign values to it's properties. I store the collection of these custom classes in the Object variable Later on in a different script task i want to read the values from this collection of custom objects.

The custom class is unknown in the other ssis components. I can't create a dll and store it on the SQL server so how to a transport the collection of custom objects.

I can get them to the script tasks and they have all the properties and correct values but there doesn't appear to be a way to accesss the properties. I duplicated the custom class and tried casting it but SSIS knows it's not the same one and won't play ball.

how do i access this data?

Erick

4

4 回答 4

0

If in fact you cannot create either a custom DLL or a custom SSIS component, your only alternative will be to use .NET reflection in your consuming scripts to find the appropriate methods/properties and access them dynamically.

That will be a significant amount of work, and the programming environment offered by SSIS isn't really conducive to it. If you really cannot deploy non-package code to your servers, I'd seriously rethink the architecture that needs that custom class.

EDIT: Simple access wasn't as hard as I thought it might be. Assuming you have a package-level variable of type Object named "SomeObject", you could build a control flow like this: demonstration control flow for passing object variables

The code for SCR_SetVariables is:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

namespace ST_00e1230a50e6470e8324a14e9d36f6c7.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
        class SomeClass
        {
            public string Greeting { get; set; }
            public override string ToString()
            {
                return String.Format("My greeting is {0}", this.Greeting);
            }
        }
        public void Main()
        {
            SomeClass myClass = new SomeClass();
            myClass.Greeting = "Hello, world!";
            Dts.Variables["SomeObject"].Value = myClass;
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }
}

and the code for SCR_ShowVariables is:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Reflection;

namespace ST_eea68a39bda44e9d9afaa07d2e48fc0f.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()
        {
            object someObject = Dts.Variables["SomeObject"].Value;
            PropertyInfo getGreeting = someObject.GetType().GetProperty("Greeting");
            string greeting = (string)getGreeting.GetValue(someObject, null);
            string msg = String.Format("someObject.Greeting = '{0}'", greeting);
            System.Windows.Forms.MessageBox.Show(msg);
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }
}

This will show the following messagebox:

resulting messagebox displaying

于 2013-10-31T17:36:18.417 回答
0

首先,如果您想在您的 SSIS 项目中正确使用自定义类库(以便能够在整个包中使用它),您必须使用强名称对您的程序集进行签名。并将其添加到 GAC。我不知道还有什么办法。然后你可以从你的项目中引用它。

另一件事是您必须使用适当范围的变量将对象图填充到某个地方。然后您可以稍后检索它,例如在其他一些脚本任务中。

高温高压

PS看到这个,最后它说把dll放在哪里所以也许你根本不需要签名(?!?)

于 2013-10-31T08:46:19.113 回答
0

我建议将您的数据存储在 DataSet 对象中 - 这样您就可以始终在其他脚本任务/组件中访问您的数据。因此,例如在您的第一个脚本任务中存储您的数据

...
DataSet dataSet = new DataSet("Data");
DataTable table = dataSet.Tables.Add("Table");
Dts.Variables["VariableOfTypeObject"].Value = dataSet;
...

并在另一个脚本任务中通过

Dataset myData = Dts.Variables{"VariableOfTypeObject"].Value as DataSet;

或者,如果您正在寻找一种将数据存储在数据流内类型为对象的 SSIS 变量中的本机方式,您可以使用“记录集目标”。

于 2013-10-31T09:04:27.177 回答
0

或者,您可以创建一个 .Net 库项目,将其添加到 GAC并在您的脚本中引用它,如果您不采取反思的方式。

于 2016-03-17T13:38:34.267 回答