7\9 SSIS 2008R2_Training - Script Task

14
7.Scripts 7.Scripts @copyright 2014 ([email protected]) . Presented by: Pramod Singla [email protected]

Transcript of 7\9 SSIS 2008R2_Training - Script Task

Page 1: 7\9 SSIS 2008R2_Training - Script Task

7.Scripts7.Scripts

@copyright 2014 ([email protected]).

Presented by: Pramod Singla

[email protected]

Page 2: 7\9 SSIS 2008R2_Training - Script Task

ContentContent Recap and Q&A Scripting in Integration Services

◦ Demo: Get the list of names from the SSIS package store Script Task Configuration

◦ Demo: Configuring a Script Task◦ Demo: Sending Email using Script taskLog method◦ Demo: Working with the Log method

Events◦ Demo: Working with the Events Member

Script Components◦ Demo: Creating a Data Transformation Script Component

Summary

@copyright 2014 ([email protected])

Page 3: 7\9 SSIS 2008R2_Training - Script Task

Recap and Q&ARecap and Q&A Split and Join Transformations

Demo: Conditional SplitDemo: MulticastDemo: Union AllDemo: MergeDemo: Merge JoinDemo: LookupDemo: Cache

Business Intelligence TransformationsDemo: SCDDemo: Fuzzy GroupingDemo: Term Extraction

Auditing Transformations Demo: Audit Demo: Row count

@copyright 2014 ([email protected])

Page 4: 7\9 SSIS 2008R2_Training - Script Task

Scripting in Integration ServicesScripting in Integration Services

Allow to perform administrative tasks programmatically

Allow to extend existing packages with custom logic using ◦ Script task and ◦ Script component.

Perform administrative tasks programmatically using following options:◦ Use the Integration Services object model to manage Integration Services

packages, folders, and roles.◦ Use the Integration Services command prompt utilities, dtexec and dtutil, to run

and manage packages.◦ Use an appropriate task in a package to run a program or batch file.

@copyright 2014 ([email protected])

Page 5: 7\9 SSIS 2008R2_Training - Script Task

Managing Integration Services Managing Integration Services Objects with the Object Model.Objects with the Object Model.

Use the object model( especially the properties and methods of the Application class) to perform the following management tasks:◦ To get a list of packages stored in a particular location◦ To determine whether an individual package or folder exists, or to manage the

folders in which packages are stored◦ To get a list of running packages and to stop a running package◦ To get a list of roles that is available on a server or assigned to a package

@copyright 2014 ([email protected])

Page 6: 7\9 SSIS 2008R2_Training - Script Task

Command Prompt UtilitiesCommand Prompt Utilities

 dtexec utility◦ Used too run an Integration Services package◦ The dtexec utility provides access to all the package configuration and execution

features, such as connections, properties, variables, logging, and progress indicators.

◦ The dtexec utility lets you load packages from three sources: a Microsoft SQL Server database, the SSIS service, and the file system.

dtutil utility◦ Can copy, move, delete, or verify the existence of a package.◦ These actions can be performed on any SSIS package that is stored in one of three

locations: a Microsoft SQL Server database, the SSIS Package Store, and the file system.

◦ The storage type of the package is identified by the /SQL, /FILE, and /DTS options. C:\Users\pram>dtutil /DTS \MSDB\myFolder\conversion /EXISTS C:\Users\pram>dtutil /FILE c:\6_2_DataFlowTransformation.dtsx /DestServer comp_4 /COPY DTS;\MSDB\destpkgname C:\Users\pram>dtutil /DTS \MSDB\destpkgname /DELETE

@copyright 2014 ([email protected])

Page 7: 7\9 SSIS 2008R2_Training - Script Task

Script Task ConfigurationScript Task Configuration

Provides code to perform functions that are not available in the built-in tasks and transformations.

If you have to use the script to do the same work for each row of data in a set, you should use the Script component instead of the Script task.

Configuring the Script Task◦ Specify the script language.◦ Optionally, provide lists of read-only and read/write variables for use in the script.◦ Specify the method in the VSTA project that the Integration Services runtime calls

as the entry point into the Script task code.

@copyright 2014 ([email protected])

Page 8: 7\9 SSIS 2008R2_Training - Script Task

Log Method(Demo)Log Method(Demo)

The Script task can use the Log method of the Dts object to log user-defined data.◦ Enable logging and ◦ select ScriptTaskLogEntry on the Details tab of the Configure SSIS

Logs dialog box to get it working

@copyright 2014 ([email protected])

Page 9: 7\9 SSIS 2008R2_Training - Script Task

Events(Emo)Events(Emo) At run time, executables (packages and Foreach Loop, For Loop, Sequence, and task host containers) raise events

@copyright 2014 ([email protected])

Event handler EventOnError The event handler for the OnError event. This event is raised by an executable when an error occurs.

OnExecStatusChanged

The event handler for the OnExecStatusChanged event. This event is raised by an executable when its execution status changes.

OnInformation The event handler for the OnInformation event. This event is raised during the validation and execution of an executable to report information.

OnPostExecute The event handler for the OnPostExecute event.

OnPostValidate The event handler for the OnPostValidate event. This event is raised by an executable when its validation is finished.

OnPreExecute The event handler for the OnPreExecute event. OnPreValidate The event handler for the OnPreValidate event. OnProgress The event handler for the OnProgress event. This event is raised by an executable when measurable

progress is made by the executable.OnQueryCancel The event handler for the OnQueryCancel event. This event is raised by an executable to determine

whether it should stop running.OnTaskFailed The event handler for the OnTaskFailed event. This event is raised by a task when it fails.OnVariableValueChanged

The event handler for the OnVariableValueChanged event. This event is raised by an executable when the value of a variable changes.

OnWarning The event handler for the OnWarning event. This event is raised by an executable when a warning occurs.

Page 10: 7\9 SSIS 2008R2_Training - Script Task

Script Components(Demo)Script Components(Demo) The Script component can be used as a

◦ source, ◦ a transformation,◦ or a destination

You can use the Script component in packages for the following purposes:◦ Apply multiple transformations to data instead of using multiple transformations in

the data flow◦ Access business rules in an existing .NET assembly. For example, a script can

apply a business rule that specifies the range of values that are valid in an Income column.

◦ Use custom formulas and functions◦ Validate column data and skip records that contain invalid dataIf the Script component contains a script that tries to read the

value of a column that is NULL, the Script component fails when you run the package

@copyright 2014 ([email protected])

Page 11: 7\9 SSIS 2008R2_Training - Script Task

SummarySummary Scripting in Integration Services

◦ Demo: Get the list of names from the SSIS package store Script Task Configuration

◦ Demo: Configuring a Script Task◦ Demo: Sending Email using Script taskLog method◦ Demo: Working with the Log method

Events◦ Demo: Working with the Events Member

Script Components◦ Demo: Creating a Data Transformation Script Component

@copyright 2014 ([email protected])

Page 12: 7\9 SSIS 2008R2_Training - Script Task

DEMO7_Scripts.dtsx 7_SSIS_DailyEmail.dtsx

Page 13: 7\9 SSIS 2008R2_Training - Script Task

@copyright 2014 ([email protected])

Page 14: 7\9 SSIS 2008R2_Training - Script Task

Resources & QuestionsResources & Questions

Contact me : ◦ [email protected]◦ http://pramodsingla.wordpress.com/

Microsoft Resources:◦ http://technet.microsoft.com/en-us/library/bb522546(v=sql.105).aspx◦ http://www.sqlsafety.com/?p=268

@copyright 2014 ([email protected])