からマッピングしたい
OleDbSource (select mFK_Prefix,mFK_Sufix,mElement_Base,mBase_Value,mPeriode_Start,mPeriode_End,mSandi_Pelapor,mOrder from [dbo].[STG_AAKL])
に
OledbDestination(select FK_Prefix,FK_Sufix,Element_Base,Base_Value,Periode_Start,Periode_End,Sandi_Pelapor,Order from [dbo].[TM_AAKL])
ssis inc# を使用して、oledbsource から oledbdestination へのマッピングをプログラムで作成する方法。
完全または私のプログラムについては、この下にあります
[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)
{
for (int i = 0; i < ComponentDestino.InputCollection[0].ExternalMetadataColumnCollection.Count; i += 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 as 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
}
}