How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Posted by Cereal Friday, April 02, 2010 12:32:43 PM Categories: _Tous les articles SQL Server 2000/2005/2008 SSIS Integration Services
Rate this Content 0 Votes
How pass parameters variables and use “Set Values” field from a “SQL Server Job” to a “SSIS Package”
In this example we create a simple “SSIS Package” that create a folder and use a path passed by a variable from “SQL Job” parameter.

Creation of a new “SSIS Package”

1.       Create a new SSIS project “MyFirstParameterSSISPackage”.
2.       Create a variable in your SSIS packages, for this example a variable “param_MyFirstParameter” type “string”.
 
http://www.simple-tech.info 
3.       Add a “Script Task” on your “Control Flow”.
4.       Edit “Script Task” to add “param_MyFirstParameter” on “ReadOnlyVariables”.
 
http://www.simple-tech.info
5.       Click on “Edit Script” button to open a new “.NET script environment”.
 
http://www.simple-tech.info
6.       Add this code in “Public Sub Main”, the code create a directory in the path stored in variable “param_MyFirstParameter”, the code return “ScriptResults.Success” if directory is successfully created and “ScriptResults.Failure” if error.
 
       Try
            'Create directory with path stored in variable "param_MyFirstParameter"
            IO.Directory.CreateDirectory(Dts.Variables("param_MyFirstParameter").Value.ToString)
            Dts.TaskResult = ScriptResults.Success
        Catch ex As Exception
            ' Return error
            Dts.TaskResult = ScriptResults.Failure
        End Try
 
 
7.       Save and close “Intergration Services Script Task”.
8.       Edit the value of variable “param_MyFirstParameter” and add “C:\MyTestFolderSSISParameter” in value.
 
http://www.simple-tech.info
9.       Run “SSIS Package” and verify that the folder “C:\MyTestFolderSSISParameter” exist in “C:” drive.
 
http://www.simple-tech.info
10.   Delete folder and remove the value field in variable “param_MyFirstParameter”.
11.   Save project.

Publish “SSIS Package” on the target server.

1.       Select package “Package.dtsx” in “Solution Explorer”.
2.       Open menu “File => Save Copy of Package.dtsx As…”.
3.       Add the destination server for publication in field “Server”.
4.       Add a “Package path” with the package name “/MyFirstParameterSSISPackage”, click “OK” button.
 
http://www.simple-tech.info
5.       Verify that the package is successfully published in your destination “Integration Services” folder in “SQL Server”.
http://www.simple-tech.info

Create the new “SQL Server” scheduled task to run your package and pass parameters

1.       Create a new job in your “SQL Server” named “JOB-MyFirstParameterSSISPackage”.
2.       Add a new “New Job Step” named “STEP-MyFirstParameterSSISPackage”.
3.       Select option “SQL Server Integration Services Package” in field “Type”.
4.       In “General” tab configure “Package source”, “Server” and set value “\MyFirstParameterSSISPackage” in “Package” field.
 
http://www.simple-tech.info
5.       In “Set values” tab, add a new “Properties Path” and “Value Field”.
“Property Path” => \Package.Variables[User::param_MyFirstParameter].Properties[Value]
“Value” => C:\MyTestFolderSSISParameter
 
http://www.simple-tech.info
6.       Save and close your job.
7.       Test your job “as step” and check that the folder is successfully created in “C:\MyTestFolderSSISParameter”.
http://www.simple-tech.info  http://www.simple-tech.info

Remark :

To pass a parameter from a “SQL Server” job to a “SSIS Package” use the convention “\Package.Variables[User::THE_VARIABLE_HERE].Properties[Value]” in “Property Path” on tab “Set values”

Download the SSIS Sample Package :

SSIS-MyFirstParameterSSISPackage.zip (85 ko)

 

Simple-Tech.info

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Tuesday, December 13, 2011 12:38:45 PM Rakesh

Thanks . good article.. :-)

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Thursday, October 27, 2011 4:04:40 PM Shyam

Wonderful suggestion. Thanks for your time.

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Saturday, July 02, 2011 7:44:48 AM Cereal

Hello,
I dont no how you can set variables dynamically but you have 2 solutions, work with config.xml files in your SSIS project, modify the content of config file before run your job or importa variables from a config file with VB.NET or C# code, where your code importe values after the start of job and set it.
I'm sorry i dont have othe issues.

Cereal

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Friday, July 01, 2011 9:13:16 AM Mahendran

Hi   Thanks  for your article .. its clear  and i have used it . its workig fine . i need  in addition  properties  are dynamic .   i need to set those properties on every   start on the job  how can i proceed please help me on this

Thanks and regards

Mahendran 

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Thursday, February 03, 2011 9:38:43 PM jeremiah

This was exactly what i was looking for. I was trying to reference the variable by it's name... didn't realize it had to be formatted in a specific format: \Package.Variables.......

 

Thanks!

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Wednesday, June 09, 2010 12:12:19 PM Cereal

I think you dont have created a variable of type "PACKAGE" in your SSIS project. Can you test with a SSIS package variable like the first picture of this document.

Best regards

CEREAL

re: How pass parameters variables and use Set Values field from a SQL Server Job to a SSIS Package

Wednesday, June 02, 2010 8:15:29 AM Rimon

Hello,

Thanks for the clear and  useful article. After I tried activate the job, it fail with the error: Could not set \package.Variables[user:: MisHevra].properties[value] value to 1 . 

(MisHevra is my variable. It defined as numeric and I gave it value 1)

What can lead to that error? 

Thanks.

Site Map | Printable View | © 2008 - 2012 Simple-Tech.info | Powered by mojoPortal | HTML 5 | CSS | Design by mitchinson