从SSIS 2012中的脚本组件中的PipelineBuffer获取列名

我试图从我的脚本组件转换中的PipelineBuffer获取列名和索引是SSIS并将它们添加到Hashtable。 我知道如果我将我的类更改为: public class ScriptMain : UserComponent to ScriptMain : PipelineComponent并使用此代码:

 public override void ProcessInput(int InputID, Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer Buffer) { inputBuffer = Buffer; hash = new Hashtable(); IDTSInput100 i = ComponentMetaData.InputCollection.GetObjectByID(InputID); foreach (IDTSInputColumn100 col in i.InputColumnCollection) { int colIndex = BufferManager.FindColumnByLineageID(i.Buffer, col.LineageID); hash.Add(col.Name, colIndex); } } 

然而; 当我这样做时,我不能再覆盖: public override void Input0_ProcessInputRow(Input0Buffer Row)因为这在PipelineComponent类中不可用,我不能再通过调用类似这样的东西来访问我的连接管理器: IDTSConnectionManager100 connMgr = this.Connections.DbConnection; 从我所看到的,UserComponent类中没有BufferManager。 有没有办法使用UserComponent完成此任务?

我的好友和我一起工作。 您可以像下面这样获取脚本缓冲区中列的名称:

 public override void Input0_ProcessInputRow(Input0Buffer inputBufferRow) { foreach (IDTSInputColumn100 column in this.ComponentMetaData.InputCollection[0].InputColumnCollection) { PropertyInfo columnValue = inputBufferRow.GetType().GetProperty(column.Name); } } 

您可以通过在脚本组件中使用reflection并将它们加载到筛选列表中来获取脚本缓冲区中的列索引和名称,如下所示:

 IList propertyList = new List(); var properties = typeof(Input0Buffer).GetProperties(); foreach (var property in properties) { if (!property.Name.EndsWith("_IsNull")) propertyList.Add(property.Name); } 

然后,您可以使用PropertyInfo对象的名称访问列表以获取脚本缓冲区中的索引值:

 int index = (propertyList.IndexOf(columnValue.Name)); 

然后,为了将其与输入管道缓冲区中的列索引相关联,您需要创建一个类属性:

 int[] BufferColumnIndexes; 

然后重写ProcessInput并从输入管道缓冲区添加映射到脚本缓冲区索引的索引:

 public override void ProcessInput(int InputID, Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer Buffer) { inputBuffer = Buffer; BufferColumnIndexes = GetColumnIndexes(InputID); base.ProcessInput(InputID, Buffer); } 

现在链接这些:

 int index = (propertyList.IndexOf(columnValue.Name)); //index in script buffer int index2 = (BufferColumnIndexes[index]); //index in input pipeline buffer