11

I'm a newbie to SSIS / C# (I'm generally a Java developer) so apologies if this is a really stupid question.

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

What I'd like to do is share some common code between the two. e.g. 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.

Does anyone know if there is a way of accomplishing what I want to do?

1

5 Answers 5

12

You're correct that there is not a straightforward way to do this directly from 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. 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. 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. If it's being used a few places here and there, consider the simple approach of 1.

1
  • 1
    the link in the other answer gives a step-by-step for #1
    – Mike M
    Jan 17, 2014 at 15:43
2

I am pretty sure it's possible to access .NET assemblies in SSIS scripts. So you could do it this way. See the article "Accessing .NET assemblies with SSIS" on SQL Server Central.

1
  • 1
    This is basically a good step-by-step for #1 in the top answer
    – Mike M
    Jan 17, 2014 at 15:43
0

I believe you will have to create an assembly or webservice for this to work.

0

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

  4. Right click on your files and add to Project

-1

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.

1
  • This works but has significant drawbacks. Each script is compiled with it's own copy of the 'shared' code and unless you touch every task that uses the referenced file, changes to the shared code will have no effect. That is, they won't automatically re-compile if the shared source changes.
    – bielawski
    May 17, 2017 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.