DATABASE

Using SQL Server 2005 Integration Services : Extensibility (part 1) - Script Tasks

7/7/2012 6:16:18 PM
Integration Services provides a very valuable and feature-rich extensible model, which is useful when the tasks and components that come with Integration Services do not supply the functionality you need. Most of the extensibility is achieved by allowing you to write your own logic in scripts, custom tasks, and custom components.

Script Tasks

A Script Task is a very simple way to introduce custom code into the execution of a package. It does not require building separate components—the code for the Script Task is stored inside the package and compiled on demand before execution. After you add a Script Task to the control flow of your package, you can immediately edit it and start entering the code. When you execute the package in SQL Server Business Intelligence Development Studio, you can set breakpoints in your script code and debug the code interactively.

Performance of Script Tasks is very good because unlike the ActiveX Task in previous versions of SQL Server, the Script Task actually compiles the scripts. The source code is compiled to Microsoft intermediate language (MSIL), which is then translated to native code during execution by the common language runtime.

The advantage of the Script Task is ease of use. The disadvantage is that the source code is in the package and therefore can be seen by anyone who can edit it (although sometimes this can be an advantage). Figure 1 shows the Script Task development environment.

Figure 1. Script Task development environment

Custom Tasks

If you want to create a reusable task component that will be distributed as a compiled assembly, you can create a custom task project. To build a custom task, create a Class Library project in Visual Studio. Add a reference to the Microsoft.SqlServer.ManagedDTS assembly. In the project properties, go to the Signing tab and select the Sign The Assembly check box. Use a key file you already have or create a key file by clicking New.

Next, create a class derived from Task and add the DtsTask attribute to the class. Build the project, and add the compiled assembly to the global assembly cache (GAC). Also copy the assembly to %ProgramFiles%\Microsoft SQL Server\90\DTS\Tasks. Restart SQL Server Business Intelligence Development Studio, and you should see your custom connection manager in the list of available connection managers.

Listing 1. Custom task example
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;

namespace CustomTask
{
[ DtsTask(
DisplayName = "Custom Task",
Description = "Description of custom task",
IconResource = "CustomTask.TaskIcon.ico" ) ]
public class CustomTask : Task
{
private int _sleepPeriod = 3000;

// TODO: Implement task properties as needed. These properties will appear
// in Properties window when you select your task in the Control Flow.
public int SleepPeriod
{
get { return _sleepPeriod; }
set { _sleepPeriod = value; }
}

public override DTSExecResult Validate(Connections connections, VariableDispenser
variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log)
{
// TODO: Add your validation code here.
return DTSExecResult.Success;
}

public override DTSExecResult Execute(Connections connections, VariableDispenser
variableDispenser, IDTSComponentEvents componentEvents,
IDTSLogging log, object transaction)
{
// TODO: Add your execution code here. The following is an example.

bool fireAgain = false;
componentEvents.FireInformation(1, "", "Sleeping for " + _sleepPeriod.ToString() + " ms"
, "", 0, ref fireAgain);
System.Threading.Thread.Sleep(_sleepPeriod);
componentEvents.FireInformation(2, "", "Woke up", "", 0, ref fireAgain);

return DTSExecResult.Success;
}
}
}			  

Other  
  •  .NET Compact Framework 3.5 : Working with Data Sets (part 3) - Reading and Writing a Data Set as XML
  •  .NET Compact Framework 3.5 : Working with Data Sets (part 2) - Data Binding
  •  .NET Compact Framework 3.5 : Working with Data Sets (part 1) - Creating and Accessing DataSet, DataTable, and DataView Objects
  •  .NET Compact Framework 3.5 : Examining ADO.NET
  •  Using SQL Server 2005 Integration Services : Programming Integration Services (part 4) - Connecting the Source and Destination Adapters with a Path
  •  Using SQL Server 2005 Integration Services : Programming Integration Services (part 3) - Setting Up Column Information
  •  Using SQL Server 2005 Integration Services : Programming Integration Services (part 2)
  •  Using SQL Server 2005 Integration Services : Programming Integration Services (part 1) - Creating Packages Programmatically - Data Flow
  •  Using SQL Server 2005 Integration Services : Working with Integration Services Packages (part 2) - Data Flow
  •  Using SQL Server 2005 Integration Services : Working with Integration Services Packages (part 1) - Control Flow
  •  SQL Server 2005 : Extending Your Database System with Data Mining - Data Mining Applied (part 2)
  •  SQL Server 2005 : Extending Your Database System with Data Mining - Data Mining Applied (part 1)
  •  # Oracle Coherence 3.5 : Achieving Performance, Scalability, and Availability Objectives (part 2)
  •  # Oracle Coherence 3.5 : Achieving Performance, Scalability, and Availability Objectives (part 1)
  •  MySQL Server Monitoring (part 3) - Server Logs, Third-Party Tools & The MySQL Benchmark Suite
  •  MySQL Server Monitoring (part 2) - MySQL Administrator
  •  MySQL Server Monitoring (part 1) - SQL Commands
  •  Using MySQL Enterprise (part 3) - Query Analyzer
  •  Using MySQL Enterprise (part 2) - Monitoring
  •  Using MySQL Enterprise (part 1) - Installation & Fixing Monitoring Agent Problems
  •  
    Top 10
    Thermalright Archon SB-E Cooler Review (Part 3)
    Thermalright Archon SB-E Cooler Review (Part 2)
    Thermalright Archon SB-E Cooler Review (Part 1)
    Acer CloudMobile - Ambitious Android Phone (Part 3)
    Acer CloudMobile - Ambitious Android Phone (Part 2)
    Acer CloudMobile - Ambitious Android Phone (Part 1)
    Huawei MediaPad 10 Tablet Review (Part 2)
    Huawei MediaPad 10 Tablet Review (Part 1)
    Mymemory.com - Calendars And Picture Books Review (Part 2)
    Mymemory.com - Calendars And Picture Books Review (Part 1)
    Most View
    iPhone 3D Programming : Adding Depth and Realism - Better Wireframes Using Polygon Offset
    Integrating Applications with the Windows Phone OS : Working with Launchers and Choosers
    What to Back Up on Exchange Servers 2010
    Samsung Galaxy Camera - Click And Share Instantly
    Optimizing an Exchange Server 2010 Environment - Properly Sizing Exchange Server 2010
    Spotlight – Money Dashboard
    SQL Server 2005 : Report Management - Publishing, SQL Server Management Studio
    How To Take Beautiful Photos By Smartphone
    Tablets Comparison (Part 1) - Google Nexus 7, Apple iPad, Microsoft surface
    How To Buy The Perfect Gear (Part 7)
    How Much Is Your Data Worth? (Part 1)
    SQL Server 2008 : Transact-SQL Programming - The OUTPUT Clause
    Dropbox : Let's "drop" your files
    Optimizing an Exchange Server 2010 Environment : Monitoring Exchange Server 2010
    Hardware With An Expiry Date (Part 2)
    Off The Shelf Or Self- Build? (Part 3)
    All The Stuff You Didn't Know (Part 4) - Booting From Backup & Dead Island Is Dead
    Examining Integration Points Between SharePoint and Public Key Infrastructure
    Enermax ETS-T40-TA – Good For Quiet Low-Mid Range System
    Building LOB Applications : Printing in a Silverlight LOB Application