为什么 SSIS 无法创建此任务? [英] Why does SSIS fail to create this task?

查看:62
本文介绍了为什么 SSIS 无法创建此任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have written this code to implement an SSIS control flow task that fetches a file over HTTP:

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 中,我使用此构建后脚本来构建和部署我的任务,以将包复制到全局程序集缓存:

In Visual Studio I build and deploy my task using this post-build script to copy the package to the global assembly cache:

"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 时,我可以在我的工具箱中看到任务:

I can see the task in my toolbox when using Business Intelligence Development Studio:

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

When I drag the task to the design window, I see this error:

任务没有出现在设计画布上.

The task does not appear on the design canvas.

我在这里做错了什么?

Siva 建议我应该使用强名称签署程序集.我遵循了 本尼奥斯汀的博客.我没有执行其他步骤,因为我的构建后脚本为我部署了组件.

Siva suggested that I should sign the assembly with a strong name. I followed steps 1 and 2 of the guide to signing assemblies on Benny Austin's blog. I didn't follow the other steps because my post-build script deploys the component for me.

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

In the Visual Studio project properties, I go to the Signing tab and create a new strong name key file for the assembly:

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

I save the settings and rebuild the package. The post-build script deploys the new package.

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

I still get exactly the same error.

推荐答案

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

I was able to recreate the issue that you are facing. Following example describes how to recreate the issue and also how to fix it. I used Visual Studio 2010 to create the class library DLL but the target framework version was 2.0. The Control Flow task was then added to SSIS 2008 R2 project, which is more or less same as SSIS 2008.

分步过程:

  1. 在 Visual Studio 2010 IDE 中,创建了一个 C# 类库项目并将其命名为 HttpTask.请参阅屏幕截图 #1.删除了除必需引用之外的所有引用.添加了对 DLL Microsoft.SQLServer.ManagedDTS 的引用,该引用位于路径 c:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SQLServer 中.ManagedDTS.dll 在我的机器上.该路径可能因您安装的 SQL Server 版本而异.路径中的 100 表示 SQL Server 2008 或 SQL Server 2008 R2.

  1. In Visual Studio 2010 IDE, created a C# class library project and named it as HttpTask. Refer screenshot #1. Deleted all the references except the required ones. Added a reference to the DLL Microsoft.SQLServer.ManagedDTS, which was available in the path c:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SQLServer.ManagedDTS.dll in my machine. The path can be different based on the version of SQL Server that you have installed. 100 in the path represents either SQL Server 2008 or SQL Server 2008 R2.

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

Renamed the class Program.cs to HttpTask.cs and pasted the code shown in screenshot #2. The code is exactly same as what is provided in the question. Code is also provided under the C# Class Code section.

在类库项目属性上,将目标框架版本更改为.NET Framework 2.0.请参阅屏幕截图 #3.

On the class library project Properties, changed the target framework version to .NET Framework 2.0. Refer screenshot #3.

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

Configured the Post-build event command line as shown in screenshots #4 and #5. The gacutil.exe path on my machine was C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe. The path could be different in your machine. The script is also provided Post-Build event command line section.

此时未对类库进行签名.请参阅屏幕截图 #6.

The class library was not signed at this time. Refer the screenshot #6.

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

The project was built but the dll was not registered in GAC (Global Assembly Cache). Refer screenshot #7.

已验证 DLL 已正确复制到路径 C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\.请参阅屏幕截图 #8.

Verified that the DLL was correctly copied to the path C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\. Refer screenshot #8.

已验证 DLL 存在于 GAC 文件夹 C:\windows\assembly 中.请参阅屏幕截图 #9.

Verified that the DLL was not present in the GAC folder C:\windows\assembly. Refer screenshot #9.

创建了一个新的 SSIS 包.在 SSIS 包的控制流选项卡的工具框中,右键单击 Control Flow Items 部分并选择 Choose Items....请参阅屏幕截图 #10.

Created a new SSIS package. On the SSIS package's Control Flow tab's tool box, right-clicked on the section Control Flow Items and selected Choose Items.... Refer screenshot #10.

在选择工具箱项上,选择SSIS 控制流项 选项卡并选择控件HTTP 任务.请参阅截图 #11.

On the Choose Toolbox Items, selected the SSIS Control Flow Items tab and selected the control HTTP Task. Refer screnshot #11.

尝试将任务拖放到控制流"选项卡上,但收到与问题中所示相同的错误.请参阅屏幕截图 #12.所以上面的步骤描述了如何模拟问题.现在,以下步骤描述了如何修复它.

Tried to drag and drop the task on to the Control Flow tab and received the same error as shown in the question. Refer screenshot #12. So the above steps described how to simulate the issue. Now, the following steps describe how to fix it.

现在,我回到类库项目并单击属性.这次我用强名称密钥签署了项目.请参阅屏幕截图 #13.

Now, I went back to the Class library project and clicked on the Properties. This time I signed the project with Strong Name Key. Refer screenshot #13.

已验证强名称密钥文件已添加到项目中.请参阅屏幕截图 #14.

Verified that the strong name key file was added to the project. Refer screenshot #14.

构建项目.这次DLL成功添加到GAC中.请参阅屏幕截图 #15.

Built the project. This time the DLL was successfully added to the GAC. Refer screenshot #15.

已验证 DLL 已正确复制到路径 C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\.请参阅屏幕截图 #8.

Verified that the DLL was correctly copied to the path C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Tasks\. Refer screenshot #8.

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

Verified that the DLL was present in the GAC folder C:\windows\assembly. Refer screenshot #16.

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

On the SSIS package, deleted the control HTTP Task from Control Flow Items section in the Toolbox. Refer screenshot #17.

重复步骤 #9 和 #10 以再次将任务添加到工具箱中.

Repeated the steps #9 and #10 to add the task again to the toolbox.

将任务拖放到控制流选项卡上,任务正确显示.这次没有错误.请参阅屏幕截图 #18.

Dragged and dropped the task on to the Control Flow tab and the task appeared correctly. There were no errors this time. Refer screenshot #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:

这篇关于为什么 SSIS 无法创建此任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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