为什么SSIS创建这个任务失败?

2024-03-24

我编写了以下代码来实现通过 HTTP 获取文件的 SSIS 控制流任务:

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

namespace HttpTask
{
    [DtsTask(
        DisplayName = "HTTP Task",
        TaskContact = "Iain Elder",
        RequiredProductLevel = DTSProductLevel.None
    )]
    public class HttpTask : Task
    {
        public string LocalPath {get; set;}
        public string Connection {get; set;}
        public bool OverwriteDestination {get; set;}

        public DTSExecResult Execute(Connections connections,
            VariableDispenser dispenser, IDTSComponentEvents events,
            IDTSLogging log, object transaction)
        {
            HttpClientConnection http = AcquireHttpConnection(connections);
            http.DownloadFile(this.LocalPath, this.OverwriteDestination);
            return DTSExecResult.Success;
        }

        private HttpClientConnection AcquireHttpConnection(Connections connections)
        {
            ConnectionManager cm = connections[this.Connection];
            object nativeConnection = cm.AcquireConnection(null);
            return new HttpClientConnection(nativeConnection);
        }
    }
}

在 Visual Studio 中,我使用此构建后脚本来构建和部署我的任务,以将包复制到全局程序集缓存:

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe" /if "$(TargetPath)"
copy $(TargetFileName) "C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks"

使用 Business Intelligence Development Studio 时,我可以在工具箱中看到该任务:

当我将任务拖到设计窗口时,我看到以下错误:

该任务不会出现在设计画布上。

我在这里做错了什么?

EDIT:希瓦建议我在大会上签署一个强有力的名字。我按照指南的步骤 1 和 2 签署程序集本尼·奥斯汀的博客 http://bennyaustin.wordpress.com/2009/06/30/steps-to-build-and-deploy-custom-ssis-components/。我没有遵循其他步骤,因为我的构建后脚本为我部署了该组件。

在 Visual Studio 项目属性中,我转到“签名”选项卡并为程序集创建一个新的强名称密钥文件:

我保存设置并重建包。构建后脚本部署新包。

我仍然得到完全相同的错误。


我能够重现您面临的问题。以下示例描述了如何重现问题以及如何修复它。我用了Visual Studio 2010创建类库DLL,但目标框架版本是2.0。然后将控制流任务添加到SSIS 2008 R2项目,与 SSIS 2008 大致相同。

分步过程:

  1. 在 Visual Studio 2010 IDE 中,创建一个 C# 类库项目并将其命名为HttpTask。参考截图#1。除必要的参考文献外,删除了所有参考文献。添加了对 DLL 的引用Microsoft.SQLServer.托管DTS,在路径中可用c:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SQLServer.ManagedDTS.dll在我的机器上。根据您安装的 SQL Server 版本,路径可能会有所不同。路径中的 100 代表 SQL Server 2008 或 SQL Server 2008 R2。

  2. 将类 Program.cs 重命名为HttpTask.cs并粘贴屏幕截图中显示的代码#2。该代码与问题中提供的代码完全相同。代码也提供在C# 类代码部分。

  3. 在类库项目 Properties 上,将目标框架版本更改为.NET Framework 2.0。参考截图#3.

  4. 配置构建后事件命令行,如屏幕截图所示#4 and #5。我机器上的 gacutil.exe 路径是C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe。您的机器中的路径可能不同。还提供了脚本构建后事件命令行部分。

  5. 此时类库尚未签名。参考截图#6.

  6. 项目已构建,但 dll 未在 GAC(全局程序集缓存)中注册。参考截图#7.

  7. 验证 DLL 是否已正确复制到路径C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\。参考截图#8.

  8. 已验证该 DLL 是not存在于 GAC 文件夹中C:\windows\assembly。参考截图#9.

  9. 创建了一个新的 SSIS 包。在 SSIS 包控制流选项卡工具箱上,右键单击该部分Control Flow Items并选择了Choose Items...。参考截图#10.

  10. 在选择工具箱项目上,选择SSIS Control Flow Items选项卡并选择控件HTTP任务。参考截图#11.

  11. 尝试将任务拖放到“控制流”选项卡上,并收到与问题中所示相同的错误。参考截图#12。所以上面的步骤描述了如何模拟这个问题。现在,以下步骤描述了如何修复它。

  12. 现在,我返回类库项目并单击“属性”。这次我用强名称密钥签署了该项目。参考截图#13.

  13. 验证强名称密钥文件是否已添加到项目中。参考截图#14.

  14. 建造了该项目。这次DLL已成功添加到GAC中。参考截图#15.

  15. 验证 DLL 是否已正确复制到路径C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\。参考截图#8.

  16. 已验证 DLL 是否存在于 GAC 文件夹中C:\windows\assembly。参考截图#16.

  17. 在 SSIS 包上,从工具箱的控制流项部分删除了控制 HTTP 任务。参考截图#17.

  18. 重复步骤#9 and #10将任务再次添加到工具箱。

  19. 将任务拖放到“控制流”选项卡上,任务就会正确显示。这次没有出现任何错误。参考截图#18.

希望有帮助。

C# 类代码:

using Microsoft.SqlServer.Dts.Runtime;

namespace HttpTask
{
    [DtsTask(
        DisplayName = "HTTP Task",
        TaskContact = "Iain Elder",
        RequiredProductLevel = DTSProductLevel.None
    )]
    public class HttpTask : Task
    {
        public string LocalPath { get; set; }
        public string Connection { get; set; }
        public bool OverwriteDestination { get; set; }

        public DTSExecResult Execute(Connections connections,
            VariableDispenser dispenser, IDTSComponentEvents events,
            IDTSLogging log, object transaction)
        {
            HttpClientConnection http = AcquireHttpConnection(connections);
            http.DownloadFile(this.LocalPath, this.OverwriteDestination);
            return DTSExecResult.Success;
        }

        private HttpClientConnection AcquireHttpConnection(Connections connections)
        {
            ConnectionManager cm = connections[this.Connection];
            object nativeConnection = cm.AcquireConnection(null);
            return new HttpClientConnection(nativeConnection);
        }
    }
}

构建后事件命令行:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" 
/if "$(TargetPath)"
copy $(TargetFileName) 
"C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\"

屏幕截图#1:

屏幕截图#2:

屏幕截图#3:

屏幕截图#4:

屏幕截图#5:

屏幕截图#6:

屏幕截图#7:

屏幕截图#8:

屏幕截图#9:

屏幕截图#10:

屏幕截图#11:

屏幕截图#12:

屏幕截图#13:

屏幕截图#14:

屏幕截图#15:

屏幕截图#16:

屏幕截图#17:

屏幕截图#18:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么SSIS创建这个任务失败? 的相关文章

随机推荐