c# - Assign custom object into Object type variable in SSIS -


i'm writing ssis scans sql table, create object each record values , need move next other ssis flow elements.

i created object type variable (myobject) , script task. in script task wrote next code:

requestobject reqobj = new requestobject(); reqobj.building = dts.variables["reqobj_building"].value.tostring(); reqobj.id = convert.toint32(dts.variables["reqobj_deviceid"].value); //... 

now tried write next code in order assin reqobj myobject.

dts.variables["myobject"].value = new requestobject(); dts.variables["myobject"].value = reqobj; 

but lines throws next run time exception :

error: system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> microsoft.sqlserver.dts.runtime.dtsruntimeexception: element cannot found in collection. error happens when try retrieve element collection on container during execution of package , element not there.  ---> system.runtime.interopservices.comexception (0xc0010009): element cannot found in collection. error happens when try retrieve element collection on container during execution of package , element not there.     @ microsoft.sqlserver.dts.runtime.wrapper.idtsvariables100.get_item(object index)    @ microsoft.sqlserver.dts.runtime.variables.get_item(object index)    --- end of inner exception stack trace ---    @ microsoft.sqlserver.dts.runtime.variables.get_item(object index)    @ st_a3e0b574a8964ffb8af6f9fee31d5afd.csproj.scriptmain.main()    --- end of inner exception stack trace ---    @ system.runtimemethodhandle._invokemethodfast(object target, object[] arguments, signaturestruct& sig, methodattributes methodattributes, runtimetypehandle typeowner)    @ system.runtimemethodhandle.invokemethodfast(object target, object[] arguments, signature sig, methodattributes methodattributes, runtimetypehandle typeowner)    @ system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture, boolean skipvisibilitychecks)    @ system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture)    @ system.runtimetype.invokemember(string name, bindingflags bindingflags, binder binder, object target, object[] providedargs, parametermodifier[] modifiers, cultureinfo culture, string[] namedparams)    @ system.type.invokemember(string name, bindingflags invokeattr, binder binder, object target, object[] args, cultureinfo culture)    @ microsoft.sqlserver.dts.tasks.scripttask.vstataskscriptingengine.executescript() 

how can assign custom object ssis object type variable ? it possible? thanks

i don't have enough reputation comment i'm adding answer instead. did below steps try , replicate problem:

  1. created new script task
  2. created new class in namespace of script
  3. created variable of type object , added script task read/write variable
  4. initialised new class , assigned value object variable.

below code ran successfully. can please explain if there thing missing/understanding wrong?

using system; using system.data; using microsoft.sqlserver.dts.runtime; using system.windows.forms;  namespace st_8eab6a8fbc79431c8c9eb80339c09d1d.csproj { public class myclass {     int a, b;      public myclass()     {         = 0;         b = 0;     } }  [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()     {         dts.taskresult = (int)scriptresults.success;         myclass m = new myclass();         dts.variables["myobject"].value = m;     } } 

}


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -