how to maping column from oledbsource to oledbdestination using SSIS in C# -


can 1 me, want make mapping

oledbsource (select mfk_prefix,mfk_sufix,melement_base,mbase_value,mperiode_start,mperiode_end,msandi_pelapor,morder [dbo].[stg_aakl]) 

to

oledbdestination(select fk_prefix,fk_sufix,element_base,base_value,periode_start,periode_end,sandi_pelapor,order [dbo].[tm_aakl]) 

how programmatically make mapping oledbsource oledbdestination using ssis inc#.

for complete or program there @ below this

[microsoft.sqlserver.dts.tasks.scripttask.ssisscripttaskentrypointattribute] public partial class scriptmain : microsoft.sqlserver.dts.tasks.scripttask.vstartscriptobjectmodelbase {        public void main()     {          string destinationcs = @"data source=.\sql2012;initial catalog=dwh_lsmk;provider=sqloledb.1;integrated security=sspi;application name=ssis-package;auto translate=false;";         string sourcecs = @"data source=.\sql2012;initial catalog=dwh_lsmk;provider=sqloledb.1;integrated security=sspi;application name=ssis-package;auto translate=false;";         generatepackage(sourcecs, destinationcs);          dts.taskresult = (int)scriptresults.success;     }     protected connectionmanager addolefbconnection(package pck, string nameconexion, string cadenaconection)     {         connectionmanager cm;         cm = pck.connections.add("oledb");         cm.connectionstring = cadenaconection;         cm.name = nameconexion;         return (cm);     }     protected virtual taskhost adddataflow(package pck,string dataflowname)     {         executable e = pck.executables.add("stock:pipelinetask");         taskhost thmainpipe = (taskhost)e;         thmainpipe.name = dataflowname;         return (thmainpipe);       }     protected virtual idtscomponentmetadata100 addsourceoledbfromtable(mainpipe flujo,string nombrecomponenete,string nombretable,connectionmanager connection )     {         idtscomponentmetadata100 conexionaoregen = flujo.componentmetadatacollection.new();         conexionaoregen.name = nombrecomponenete;         conexionaoregen.componentclassid = "dtsadapter.oledbsource";         cmanagedcomponentwrapper instance = conexionaoregen.instantiate();         instance.providecomponentproperties();         conexionaoregen.runtimeconnectioncollection[0].connectionmanager = dtsconvert.getextendedinterface(connection);         conexionaoregen.runtimeconnectioncollection[0].connectionmanagerid = connection.id;         conexionaoregen.name = nombrecomponenete;         instance.setcomponentproperty("accessmode",0);         instance.setcomponentproperty("openrowset", nombretable);         try         {             instance.acquireconnections(null);             instance.reinitializemetadata();             instance.releaseconnections();         }         catch (exception e)         {             throw;          }         return (conexionaoregen);     }     protected virtual idtscomponentmetadata100 addoledbdestinationtable(mainpipe dataflowtask,connectionmanager destinationconnection,idtscomponentmetadata100 fuentedatos,string tabledestination)     {         idtscomponentmetadata100 componentdestino = dataflowtask.componentmetadatacollection.new();         componentdestino.componentclassid = "dtsadapter.oledbdestination";         cmanagedcomponentwrapper instance = componentdestino.instantiate();         instance.providecomponentproperties();         componentdestino.runtimeconnectioncollection[0].connectionmanager = dtsconvert.getextendedinterface(destinationconnection);         componentdestino.runtimeconnectioncollection[0].connectionmanagerid = destinationconnection.name;         instance.setcomponentproperty("accessmode",3);         //instance.setcomponentproperty("fastloadoptions","tablock,check_constraints");         instance.setcomponentproperty("openrowset", tabledestination);         idtspath100 union = dataflowtask.pathcollection.new();         union.attachpathandpropagatenotifications(fuentedatos.outputcollection[0], componentdestino.inputcollection[0] );         instance.acquireconnections(null);         instance.reinitializemetadata();         instance.releaseconnections();           foreach (idtsoutputcolumn100 col in fuentedatos.outputcollection[0].outputcolumncollection)         {              (int = 0; < componentdestino.inputcollection[0].externalmetadatacolumncollection.count; += 1)             {                 string campo = componentdestino.inputcollection[0].externalmetadatacolumncollection[i].name;                     if ((col.name.toupper() == "mperiode_start") && (campo.toupper() == "periode_end"))                 {                     idtsinputcolumn100 colnueva = componentdestino.inputcollection[0].inputcolumncollection.new();                     colnueva.lineageid = col.id;                     colnueva.externalmetadatacolumnid = col.id;                     colnueva.mappedcolumnid = col.id;                     colnueva.name = col.name;                     // break;                 }                 else if ((col.name.toupper() == "mperiode_end") && (campo.toupper() == "periode_start"))                 {                     idtsinputcolumn100 colnueva = componentdestino.inputcollection[0].inputcolumncollection.new();                     colnueva.lineageid = col.id;                     colnueva.externalmetadatacolumnid = col.id;                     colnueva.mappedcolumnid = col.id;                     colnueva.name = col.name;                     //break;                  }               }         }         foreach (idtsinputcolumn100 inputcolumn in componentdestino.inputcollection[0].inputcolumncollection)             console.writeline(inputcolumn.name);         console.read();          return (componentdestino);       }     public void generatepackage(string sourceconnectionstring, string destinationconnectionstring)     {         oledbconnection cn = new oledbconnection(sourceconnectionstring);         cn.open();         package mipk = new package();         mipk.name = "kbgk_aakl";         application app = new application();         connectionmanager connorigen = addolefbconnection(mipk, "source", sourceconnectionstring);         connectionmanager conndestina = addolefbconnection(mipk, "destination", destinationconnectionstring);         mainpipe df = adddataflow(mipk,"kbgk aakl").innerobject mainpipe ;         idtscomponentmetadata100 source = addsourceoledbfromtable(df, "source component", "stg_aakl", connorigen);         addoledbdestinationtable(df, conndestina,source,"tm_aakl" );         app.savetoxml(string.format(@"d:\\lsmk-source\\ssis\\autogenerate\\autogenerate_aakl.dtsx", mipk.name), mipk, null);        }      #region scriptresults declaration      enum scriptresults     {         success = microsoft.sqlserver.dts.runtime.dtsexecresult.success,         failure = microsoft.sqlserver.dts.runtime.dtsexecresult.failure     };     #endregion  } 

}

try using bulkcopy function... ridoff dft ....


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -