Tuesday, April 27, 2010

Creating a DLL for a common C# module

While writing C# code or VB code inside a script task, it is always a good practice to encapsulate methods that are used multiple times across the various script tasks.. It saves you the pain of opening each script task each time you have to change something in the functionality of the module..

For those, who have difficulty integrating C# code with SSIS, here are some notes..

How to generate a DLL from a C# class (.cs) file that contains the common methods..

A good reference link to create a .cs file for your methods - MSDN

1. Make sure you have Visual Studio installed for Visual C# - only then the below steps will make sense..

2. Create new project --> File --> New -->  Project -->  Visual C# --> Class Library project




3. Add the class (.cs) file that you have already created to the project. Right click on the project in the Solution Explorer --> Add --> Existing Item and choose the .cs file.

4. In the menu bar, select "Build--> Build <projectname>"

5. If the build succeeds, check the path --> project path\bin\Debug\ for the .dll file. It should be generated after the successful build.

6. Copy this .dll file to the C:\Program Files\Microsoft SQL Server\100\DTS\Binn folder to use it within the SSIS script task.

How to use the DLL file in the script task

1. Inside the script task's project explorer, right click on "References" tab to "Add Reference" to the DLL file.


2. In the .NET tab of the "Add Reference" Dialog box, choose the DLL file that you just created.



If you did not place the DLL file in the \Binn\ folder, you will not see it in this list.

Also, if you did choose the path to the DLL file using the "Browse" or "Recent" tabs in the above dialog box, it will not throw any compilation errors. However, you will face RunTime errors....


No comments:

Post a Comment