Return to site

Script Task Editor Ssis

broken image


The Script Task was used heavily to demonstrate how the SSIS scripting environment works with Visual Studio and during the execution of a package. Generally, anything that you can script in the.NET managed environment that should run once per package or code loop belongs in the Script Task. Run PowerShell scripts in SSIS First published on MSDN on Jan 26, 2017 PowerShell is a powerful task automation tool from Microsoft. With Azure PowerShell cmdlets, you can write PowerShell scripts to automate various Azure-related tasks. Let's learn the task by customizing the package Variables.dtsx which we created in previous section. Open the package Variables.dtsx in design mode. Drag and drop the Script Task from SSIS Toolbox to the package. Then right click the Script Task and choose 'Edit.' The Script Task Editor.

By: Koen Verbeeck
Overview

It's time to start building an SSIS package. In this chapter, we'lladd tasks to the control flow and learn how you can start the debugger to executethe package. We'll also look how the execution of different tasks can be relatedto each other.

Adding Tasks to the SSIS Control Flow

Let's start by adding an Execute SQL Task to the control flow. You caneither drag it from the SSIS toolbox to the control flow, or you can double clickit.

You can see there's a red error icon on the task. That's becausewe haven't defined a database connection yet.

Double click the task to open it. In the editor, open the connectiondropdown and click on .

Script task editor ssis

If you have already created connection managers, you can pick one from the listin the next window. However, you can also create a new one by clicking the New…button at the bottom.

This will open a connection manager editor. You need to enter the server nameand select a database from the dropdown list. You can also optionally specify ausername and password if you don't want to use Windows Authentication.

Click OK two times to go back to the Execute SQL Task editor. You can eitherdirectly type a SQL statement in the SQLStatement property or you can clickon the ellipsis to open up the editor. This editor is basically a notepad editorand it has no additional functionality. You are most likely better off writingSQL statements in Management Studio and copy pasting them into the editor. Let'senter a very basic statement: SELECT 1.

Telerik mvc grid date format. Click OK to close the editor.

Executing SSIS Packages

We can now run the package to test our Execute SQL Task. You can click on thegreen arrow or just hit F5. This will start the debugger which will run the package.

When the task has finished, you will see a green icon in the corner of the task.You can click on the stop icon in the task bar to stop the debugger or you can clickon the sentence below the connection manager window.

When the package is running, an extra tab is added called Progress.Here you can see all of the informational messages, errors and warnings generatedby the SSIS package as well as timing information.

When the debugger stops, the Progress tab is renamed to Execution Results.

SSIS Precedence Constraints

With precedence constraints, we can influence how different tasks impact eachother. Let's start by creating a copy of our Execute SQL Task. Now when we execute the package, both tasks will be executed in parallel.

You can create a precedence constraint by selecting the first task and draggingthe green arrow to the other task. Now when we execute the package, the first taskswill be executed and then the other.

The green arrow signifies a 'Success' precedence constraint, whichmeans the second task will only be executed if the first task is successful. Youcan change the behavior of the precedence constraint by double clicking on the arrow:

You can change the precedence constraint to 'Failure', which meansthe second task will only be executed if the first task fails. With 'Completion',the second tasks will execute once the first task has finished, but it doesn'tmatter if the first task was successful or not. When you have multiple arrows goinginto one single task, you can change the constraint to AND or OR. With AND, alltasks need to be successful before the task starts. With OR, only one task needsto be successful. In the following screenshot, only one of the two top tasks mustfinish successfully so the last task can start.

With precedence constraints and containers, you can create complex workflows:

Additional Information
  • For more details on precedence constraints, check out the tipDefining Workflow in SSIS using Precedence Constraints.

Last Update: 8/31/2017
Task
We often have to debug Script task which we have used in ourSSIS Package. We use MessageBox.show to see the value of variables and thenhave to hit Ok to see the next value. Instead of introducing Message Boxes fordebugging we can use Break Point and debug step by step so we do not have toworry about removing the Message Boxes or commenting them after debug. In case we forget any of them that can becomethe reason of package failure when we will be running the package from SQLServer Agent.
Let's jump into an example, how to debug Script Task step bystep by using Break Point.
In this sample Package, I am reading the file names from afolder. I have created a Variable FolderPath in SSIS Package and passed thisvariable to Script Task. Script Task uses this folder path and read the filenames.
Fig 1: FolderPath Variable holding the Folder path

First, I want to make sure the Script task is readingthe correct value of FolderPath variable and then want to know what file namesare read from Folder?
Drag Script Task to Control Flow Surface, Open it by double clicking and then provide the FolderPath variable to it and Click on Edit Script. I am using C# for scripting, you can use VB.Net if you like.
Fig 2: Provide the Variable FolderPath to Script Task
Add using System.IO under namespaces and below code in Main. The code is going to read the .txt files from the Folder which is provided by FolderPath variable.
DirectoryInfo dir = new DirectoryInfo(Dts.Variables['User::FolderPath'].Value.ToString());

Script Task Editor Ssis

foreach (FileInfo file in Files)

Ssis Upgrade Script Task

string variable = file.Name;

Ssis Script Task Transformation

Fig 3: Break Point in Script Task
Hit the Save button and close the Script Task Edit window. You will see that the Script Task has Red Circle that means Break Point is added to the Script Task.
Fig 4: Script Task After Break Point added
Examples

If you have already created connection managers, you can pick one from the listin the next window. However, you can also create a new one by clicking the New…button at the bottom.

This will open a connection manager editor. You need to enter the server nameand select a database from the dropdown list. You can also optionally specify ausername and password if you don't want to use Windows Authentication.

Click OK two times to go back to the Execute SQL Task editor. You can eitherdirectly type a SQL statement in the SQLStatement property or you can clickon the ellipsis to open up the editor. This editor is basically a notepad editorand it has no additional functionality. You are most likely better off writingSQL statements in Management Studio and copy pasting them into the editor. Let'senter a very basic statement: SELECT 1.

Telerik mvc grid date format. Click OK to close the editor.

Executing SSIS Packages

We can now run the package to test our Execute SQL Task. You can click on thegreen arrow or just hit F5. This will start the debugger which will run the package.

When the task has finished, you will see a green icon in the corner of the task.You can click on the stop icon in the task bar to stop the debugger or you can clickon the sentence below the connection manager window.

When the package is running, an extra tab is added called Progress.Here you can see all of the informational messages, errors and warnings generatedby the SSIS package as well as timing information.

When the debugger stops, the Progress tab is renamed to Execution Results.

SSIS Precedence Constraints

With precedence constraints, we can influence how different tasks impact eachother. Let's start by creating a copy of our Execute SQL Task. Now when we execute the package, both tasks will be executed in parallel.

You can create a precedence constraint by selecting the first task and draggingthe green arrow to the other task. Now when we execute the package, the first taskswill be executed and then the other.

The green arrow signifies a 'Success' precedence constraint, whichmeans the second task will only be executed if the first task is successful. Youcan change the behavior of the precedence constraint by double clicking on the arrow:

You can change the precedence constraint to 'Failure', which meansthe second task will only be executed if the first task fails. With 'Completion',the second tasks will execute once the first task has finished, but it doesn'tmatter if the first task was successful or not. When you have multiple arrows goinginto one single task, you can change the constraint to AND or OR. With AND, alltasks need to be successful before the task starts. With OR, only one task needsto be successful. In the following screenshot, only one of the two top tasks mustfinish successfully so the last task can start.

With precedence constraints and containers, you can create complex workflows:

Additional Information
  • For more details on precedence constraints, check out the tipDefining Workflow in SSIS using Precedence Constraints.

Last Update: 8/31/2017
We often have to debug Script task which we have used in ourSSIS Package. We use MessageBox.show to see the value of variables and thenhave to hit Ok to see the next value. Instead of introducing Message Boxes fordebugging we can use Break Point and debug step by step so we do not have toworry about removing the Message Boxes or commenting them after debug. In case we forget any of them that can becomethe reason of package failure when we will be running the package from SQLServer Agent.
Let's jump into an example, how to debug Script Task step bystep by using Break Point.
In this sample Package, I am reading the file names from afolder. I have created a Variable FolderPath in SSIS Package and passed thisvariable to Script Task. Script Task uses this folder path and read the filenames.
Fig 1: FolderPath Variable holding the Folder path

First, I want to make sure the Script task is readingthe correct value of FolderPath variable and then want to know what file namesare read from Folder?
Drag Script Task to Control Flow Surface, Open it by double clicking and then provide the FolderPath variable to it and Click on Edit Script. I am using C# for scripting, you can use VB.Net if you like.
Fig 2: Provide the Variable FolderPath to Script Task
Add using System.IO under namespaces and below code in Main. The code is going to read the .txt files from the Folder which is provided by FolderPath variable.
DirectoryInfo dir = new DirectoryInfo(Dts.Variables['User::FolderPath'].Value.ToString());

Script Task Editor Ssis

foreach (FileInfo file in Files)

Ssis Upgrade Script Task

string variable = file.Name;

Ssis Script Task Transformation

Fig 3: Break Point in Script Task
Hit the Save button and close the Script Task Edit window. You will see that the Script Task has Red Circle that means Break Point is added to the Script Task.
Fig 4: Script Task After Break Point added
Let's execute our SSIS Package and see how we can debug the Script Task and see the values of variables etc. As we can see the Script Task is stopped at Break Point.

Fig 5: Execution stopped at Break Point
Once you hit F10 or F11 , the next step will be highlighted and executed as shown below.
Fig 6: Debug step by step by using F10 or F11

Ssis Script Task Editor Read Only Variables

As you can see in the fig 6, we can click on the line and it will show us the value. you can unpin or pin to see or hide the values while debugging.
Once the Script Task execution is completed, the package will return to run next task in Control Flow Surface. If all looks fine to you. Open the Script Task and Click on the Break Point to remove it.




broken image