SSIS API:如何知道将 __COMObject 转换为哪个接口? [英] SSIS API: How does one know what Interface to cast a __COMObject to?

查看:23
本文介绍了SSIS API:如何知道将 __COMObject 转换为哪个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章,我也在尝试从 SSIS 包中提取 SQL.我想我会尝试发布的相同代码.听起来代码对他有用,但不完整,因为它没有处理所有可能的情况.这是调用proc的代码

Like this post, I am also trying to extract SQL from an SSIS package. I thought I would try the same code that was posted. It sounded like the code worked for him but was incomplete because it did not handle all of the possible scenarios. Here's the code to call the proc

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);

从帖子中,这是过程:

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)).

我尝试使用此方法获取接口列表,但返回了一个空数组

I tried this to get a list of interfaces, but an empty array was returned

        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 对象转换为哪个接口.怎么知道的?

I guess my issue is knowing what Interface to cast these COM objects to. How does one know?

由于缺乏打字,我也对任务可能需要哪些库感到困惑.看起来有 COM 版本以及托管包装器.我希望托管包装器会给我强类型对象而不是 __COMObject,但也许不会.我刚开始玩,我不知道从哪里开始.如果有人对我可能需要参考哪些库以从 SSIS 包中提取 SQL 的任务提出意见,我将不胜感激.我可能还需要提取有关哪些源文件传输到哪些 dest 表的一般信息.

With this lack of typing, I am also confused about which libraries I may need for the task. It looks like there are COM versions as well as managed wrappers. My hope was that the managed wrappers would give me strongly typed objects instead of __COMObject, but maybe not. I just starting playing around and I'm not sure where to begin. If someone had comments about which libraries I may need to reference for the task of pulling out SQLs from SSIS packages, I'd appreciate it. I may also need to extract general info as to what source files are transferred to which dest tables.

  1. Microsoft.SqlServer.DTSPipelineWrap.dll
  2. Microsoft.SQLServer.DTSRuntimeWrap.dll
  3. Microsoft.SQLServer.ManagedDTS.dll
  4. Microsoft.SqlServer.PipelineHost.dll
  5. Microsoft.SqlServer.ScriptTask.dll

推荐答案

猜测您没有 DTS 对象的路径.

Guessing you don't have a path to the DTS objects.

试试这个.仔细检查您是否有系统路径变量:c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\

Try this. Double check that you have system path varibles: c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\

路径中的100"是sql server 2008.110"是sql server 2012.它们需要出现在您路径中的110"版本之前.

"100" in the path is sql server 2008. "110" is sql server 2012. They need to appear prior to the "110" versions in your path.

这篇关于SSIS API:如何知道将 __COMObject 转换为哪个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆