2013-02-07 54 views
1

我正在使用.NET從SSIS包中提取元數據。從SSIS包中提取映射列

有沒有一種方法來提取來自OLEDB源的映射信息(沒有變量用於語句),它的目的地?

回答

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代碼來編譯。

+0

嗨埃德蒙,這是否適用於序列容器內的數據流?當我在序列容器中傳遞數據流任務的名稱時,我相信包中唯一的可執行文件就是容器本身。 – dirtyw0lf

+0

是的,雖然在這種情況下你需要兩個步驟。首先,從程序包的'Executables'集合中獲取Sequence。接下來,從Sequence對象的'Executables'集合中獲取DataFlow。 –

+0

還有一點比從Executables集合獲取DataFlow還要多。 http://www.sqlis.com/sqlis/post/Searching-for-tasks.aspx – dirtyw0lf