从SSIS包中提取映射列

时间:2013-02-07 18:50:13

标签: ssis mapping

我正在使用.NET从SSIS包中提取元数据。

有没有办法从和OLEDB源(没有用于语句的变量)及其目的地中提取映射信息?

1 个答案:

答案 0 :(得分:1)

是的,虽然您必须深入研究IDTSPipeline100和相关接口的杂草,但这样做:

using System;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace CSharpConsoleApp
{
    class PackageDemo
    {
        public void CountColumns(string packagePath, string dataFlowName)
        {
            Application app = new Application();
            Package package = app.LoadPackage(packagePath, null);

            TaskHost th = package.Executables[dataFlowName] as TaskHost;
            MainPipe mp = th.InnerObject as MainPipe;
            foreach (IDTSComponentMetaData100 md in mp.ComponentMetaDataCollection)
            {
                foreach (IDTSOutput100 output in md.OutputCollection)
                {
                    Console.WriteLine("Component {0} output {1} has {2} columns", 
                        md.Name, output.Name, output.OutputColumnCollection.Count);
                    foreach (IDTSOutputColumn100 column in output.OutputColumnCollection)
                    {
                        Console.WriteLine("\tcolumn {0} ({1}) is of type {2}", 
                            column.ID, column.Name, column.DataType);
                    }
                }
            }
        }
    }
}

请注意,您需要引用Microsoft.SqlServer.ManagedDTSMicrosoft.SqlServer.DtsPipelineWrapMicrosoft.SqlServer.DtsRuntimeWrap DLL才能编译此代码。