3

这篇文章一样,我也在尝试从 SSIS 包中提取 SQL。我想我会尝试发布的相同代码。听起来代码对他有用,但不完整,因为它没有处理所有可能的情况。这是调用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);

从帖子中,这是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 的任务有意见,我将不胜感激。我可能还需要提取关于哪些源文件传输到哪些目标表的一般信息。

  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
4

2 回答 2

0

这就是我从 Execute SQl 任务中提取 SQL 的方式:

                foreach (Executable executable in _Package.Executables)
                {
                    TaskHost taskHost = executable as TaskHost;
                    if (taskHost != null)
                    {
                        string taskHostName = taskHost.Name;
                        System.Diagnostics.Debug.WriteLine("SSIS Task=" + taskHostName);

                        IDTSExecuteSQL iDTSExecuteSQL;

                        try
                        {
                            iDTSExecuteSQL = (IDTSExecuteSQL)taskHost.InnerObject as IDTSExecuteSQL;

                            if (iDTSExecuteSQL != null)
                            {

现在,如果我能弄清楚如何从数据任务中提取 sql:

 MainPipe pipeline = taskHost.InnerObject as MainPipe;
                                    if (pipeline != null)
                                    {
                                        foreach (IDTSComponentMetaData100 componentMetadata in pipeline.ComponentMetaDataCollection)
                                        {
                                            try
                                            {???

怎么办??

于 2013-06-11T00:41:19.300 回答
0

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

尝试这个。仔细检查您是否有系统路径变量: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服务器\100\DTS\Binn\

路径中的“100”是 sql server 2008。“110”是 sql server 2012。它们需要出现在路径中的“110”版本之前。

于 2013-07-29T23:34:41.747 回答