與this post一樣,我也試圖從SSIS包中提取SQL。我以爲我會嘗試發佈相同的代碼。這聽起來像代碼爲他工作,但不完整,因爲它沒有處理所有可能的情況。下面的代碼來調用PROCSSIS API:如何知道將什麼接口投射到__COMObject?
var taskHost = (Microsoft.SqlServer.Dts.Runtime.TaskHost)_Package.Executables[0];
var innerObject = taskHost.InnerObject;
List<TaskHost> listOfTaskHosts = new List<TaskHost>();
listOfTaskHosts.Add(taskHost);
string sql = ExtractQueriesFromTasks(listOfTaskHosts);
從後,這裏的PROC:
public static string ExtractQueriesFromTasks(List<TaskHost> Tasks)
{
string src_query = "";
foreach (TaskHost executable in Tasks)
{
DtsContainer Seq_container = (DtsContainer)executable;
if (executable.InnerObject is TaskHost)
{
TaskHost th = (TaskHost)executable.InnerObject;
string n = th.InnerObject.GetType().Name;
}
if (executable.InnerObject.GetType().Name == "__ComObject")
{
Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSPipeline100 sqlTask1 = (Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSPipeline100)executable.InnerObject;
}
}
return src_query;
}
我得到這個
{System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSPipeline100'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{89CEBA86-EC51-4C62-A2D3-E9AA4FC28900}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
我嘗試這樣得到的接口列表,但返回空陣列
if (executable.InnerObject.GetType().Name == "__ComObject")
{
Type[] types = (executable.InnerObject.GetType()).GetInterfaces();
foreach (Type currentType in types)
{
if (typeof(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSPipeline100).IsAssignableFrom(executable.InnerObject.GetType()))
{
Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSPipeline100 sqlTask1 = (Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSPipeline100)executable.InnerObject;
}
}
我想我的問題是知道什麼接口投這些COM對象。人們如何知道?
由於缺少輸入,我也對我可能需要哪些庫進行任務感到困惑。它看起來像COM版本以及託管封裝。我的希望是,託管的包裝會給我強類型的對象,而不是__COMObject,但可能不會。我剛開始玩,我不知道從哪裏開始。如果有人評論了我可能需要引用哪些庫來完成從SSIS包中提取SQL的任務,那麼我會很感激。我可能還需要提取關於哪些源文件傳輸到哪個目標表的一般信息。
- Microsoft.SqlServer.DTSPipelineWrap.dll
- Microsoft.SQLServer.DTSRuntimeWrap.dll
- Microsoft.SQLServer.ManagedDTS.dll
- Microsoft.SqlServer.PipelineHost.dll
- Microsoft.SqlServer。 ScriptTask.dll
我不知道這是你問什麼,但我發現'微軟。 VisualBasic.Information.TypeName(obj)'有用(正如這裏提到的http://www.mztools.com/articles/2006/mz2006013.aspx)在處理'__COMObject's之前。 –
謝謝,看起來很有趣。我正在檢查它...... – ChadD
起初,我認爲這是一個工具來幫助我確定投入COM對象的類型,但我認爲這只是一個相關的提示。我試過這個:string name = Microsoft.VisualBasic.Information.TypeName(executable.InnerObject); 正如預期的那樣,這仍然返回「__COMObhect」,就像GetType方法一樣。 – ChadD