简体   繁体   English

SSIS并重新使用C#

[英]SSIS and re-using C#

I'm a newbie to SSIS / C# (I'm generally a Java developer) so apologies if this is a really stupid question. 我是SSIS / C#的新手(我通常是一名Java开发人员),如果这是一个非常愚蠢的问题,请道歉。

Essentially the problem is this: I have two Data Flow tasks which load data up and export them to a legacy flat file format. 本质上问题是:我有两个数据流任务,它们加载数据并将它们导出为传统的平面文件格式。 The formatting is done by a Script Task (C#). 格式化由脚本任务(C#)完成。

What I'd like to do is share some common code between the two. 我想做的是在两者之间分享一些共同的代码。 eg I could create a common base class and then extend it for my two different script tasks. 例如,我可以创建一个公共基类,然后为我的两个不同的脚本任务扩展它。

However it seems that SSIS doesn't really make provision for this. 然而,似乎SSIS并没有真正为此做好准备。

Does anyone know if there is a way of accomplishing what I want to do? 有谁知道是否有办法完成我想做的事情?

You're correct that there is not a straightforward way to do this directly from SSIS. 你是正确的,没有直接从SSIS直接这样做的方法。

In a recent project, we took two different approaches, which both worked fairly well depending on what you need to do: 在最近的一个项目中,我们采用了两种不同的方法,根据您的需要,它们都能很好地工作:

  1. Create a utility class (as a simple class library) and reference it from your script tasks. 创建一个实用程序类(作为一个简单的类库)并从脚本任务中引用它。 This is done pretty much the same as any other sort of reference. 这与其他任何类型的引用几乎完全相同。 If you use .NET 3.5, remember that you'll have to update the version manually in the script tasks since SSIS defaults to 2.0. 如果您使用.NET 3.5,请记住您必须在脚本任务中手动更新版本,因为SSIS默认为2.0。 We also found that if we wanted some manner of reusability in the utility assembly (not relying on hardcoded variable names, etc.) then the package still had to have a fairly large amount of "setup" boilerplate to use the utility scripts. 我们还发现,如果我们想要在实用程序程序集中使用某种方式的可重用性(不依赖于硬编码的变量名等),那么程序包仍然必须具有相当大量的“设置”样板才能使用实用程序脚本。

  2. Create a custom data flow component. 创建自定义数据流组件。 This is a much more involved process, but ultimately will do the best in terms of avoiding code duplication. 这是一个涉及更多的过程,但最终将在避免代码重复方面做到最好。 Generally, coding the actual data flow is fairly simple and not that much different than a script component, but the various setup code you'll need can tend to make things complicated. 通常,对实际数据流进行编码非常简单,与脚本组件没有太大区别,但是您需要的各种设置代码往往会使事情变得复杂。 There's also not a lot of support in SSIS for when something goes wrong. 当出现问题时,SSIS也没有太多的支持。 Led to a lot of detective work on our project. 导致我们项目的很多侦探工作。

If you plan on using something a whole lot, and are committed to getting rid of boilerplate code as much as possible, 2 is the preferred option. 如果你计划使用很多东西,并且尽可能地去掉样板代码,那么2是首选。 If it's being used a few places here and there, consider the simple approach of 1. 如果在这里和那里使用了几个地方,请考虑1的简单方法。

I am pretty sure it's possible to access .NET assemblies in SSIS scripts. 我很确定可以在SSIS脚本中访问.NET程序集。 So you could do it this way. 所以你可以这样做。 See the article "Accessing .NET assemblies with SSIS" on SQL Server Central. 请参阅SQL Server Central上的文章“使用SSIS访问.NET程序集”

This does not completely solve your issue but it does help in not having to recreate all the classes every time you need them (I also do not want to deploy referenced assemblies for my current project ). 这并不能完全解决您的问题,但它确实有助于您不必在每次需要时重新创建所有类(我也不想为当前项目部署引用的程序集)。 Firstly you need a master copy of your classes, you can copy them from an existing Script Task using the same process below but in reverse. 首先,您需要一个类的主副本,您可以使用下面相同的过程从现有的脚本任务中复制它们,但反之亦然。

  1. Open the Editor for the Script Task and on the Property Explorer click on the Project File (the st_[Guid] ), in the Properties window you'll see the Project Folder location. 打开脚本任务的编辑器,在Property Explorer上单击项目文件(st_ [Guid]),在Properties窗口中,您将看到Project Folder位置。 (This location gets recreated every time you edit the script task) (每次编辑脚本任务时都会重新创建此位置)

  2. In explorer, copy your classes to this folder 在资源管理器中,将您的类复制到此文件夹

  3. On the Project Explorer, click on the “Show All Files” icon 在Project Explorer中,单击“显示所有文件”图标

  4. Right click on your files and add to Project 右键单击您的文件并添加到Project

我相信你必须创建一个程序集或web服务才能工作。

Probably way too late to answer this, but you can click on the solution and add a class there. 可能为时已晚,无法回答这个问题,但您可以点击解决方案并在那里添加课程。 Then when you go into your scripts you can say add existing object and search for that class you created earlier. 然后,当您进入脚本时,您可以说添加现有对象并搜索您之前创建的该类。 For me it was located by the solution for the project. 对我来说,它是由项目的解决方案找到的。 Haven't gone through the deployment or anything for this, but at least you can access the class through the individual scripts. 没有经历过部署或任何事情,但至少你可以通过各个脚本访问该类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM