Packages can be run in various wizards and applications; however, packages are most often run in SQL Server Business Intelligence Development Studio (BIDS) during the development, debugging, and testing of packages. The Execute Package task extends the enterprise capabilities of SSIS by enabling packages to run other packages as part of a workflow. A package that runs another package is generally referred to as a parent package, and the packages that a parent workflow runs are called child packages. This section discusses the various methods for creating and executing packages.
The SQL Server Import and Export Wizard provides the simplest method for creating and executing a simple package. You can start the SQL Server Import and Export Wizard from an Integrations Services package in BIDS, or you can start the wizard from SQL Server Management Studio; however, you can execute a package only if you start the SQL Server Import and Export Wizard in SQL Server Management Studio.
In BIDS, create an SSIS project by performing the following steps:
On the File menu, click New, and then click New Project.
In the New Project dialog box, provide a name, location, and solution for your project, and then click OK.
In Solution Explorer, right-click the SSIS packages folder, and then click SSIS Import And Export Wizard. The SQL Server Import And Export Wizard appears.
Follow the wizard steps, and then save the package in your project.
Note | A package cannot be executed if you start the SQL Server Import And Export Wizard from an Integrations Services package in BIDS. |
In Management Studio, connect to a database engine by performing the following steps:
On the File menu, click Connect Object Explorer. The Connect to Server dialog box appears.
Click Connect.
In Object Explorer, expand the Databases folder.
Right-click the name of the database you created earlier (configdb), click Tasks, and then click either Import Data or Export Data. The SQL Server Import And Export Wizard appears.
Follow the wizard steps, save the package, and then decide whether to execute the package.
Another effective tool for executing packages is the SSIS package execution utility DTExecUI. DTExecUI is a command prompt utility that enables you to run packages from a command prompt or from within SQL Server Management Studio.
To open a command prompt window, click Start, and then click Run. The Run box appears.
In the command prompt window, type dtexecui, and then press Enter. The Execute Package Utility dialog box opens.
In the Execute Package Utility dialog box, specify any of the following:
Package to execute
XML configuration files
Connection Manager connection strings
Variables
Other package properties
Click Execute to run the package. Wait until the package has executed successfully.
The DTExec utility provides access to all the package configuration and execution features, such as connections, properties, variables, logging, and progress indicators. It enables you to load packages from three sources: a SQL Server database, the SSIS service, and the Windows file system.
The DTExec utility proceeds through four phases as it executes:
Command sourcing phase
Package load phase
Configuration phase
Validation and execution phase
DTExec enables you to run packages from a command prompt. The basic syntax is dtexec /option [value] [/option [value]]. The Execute Package Utility contains a command-line window. This window contains the /option [value] part of the dtexec syntax. The dtexec command can be saved in a *.bat or *.cmd file, and then the package can be run by executing one of these files. This is particularly useful with enterprise job-scheduling software. The SSIS developers can create the *.cmd files, and then the job-scheduling software needs only to execute the *.cmd files.
On a 64-bit server, the 64-bit version of dtexec.exe is located at \Program Files\Microsoft SQL Server\90\DTS\Binn\DTExec.exe. The 32-bit version of dtexec.exe is located at \Program Files\Microsoft SQL Server (x86)\90\DTS\Binn\DTExec.exe. It is sometimes useful to execute SSIS in 32-bit mode on a 64-bit server. For example, there is no 64-bit Microsoft Access OLE DB (Jet engine) driver.
More Info | For more information about the DTExec utility, see the SQL Server 2005 Books Online article titled "dtexec Utility" at http://msdn2.microsoft.com/en-us/library/ms162810.aspx. |
Open a command prompt window.
In the command prompt window, type dtexec / followed by the DTS, SQL, or File option and the package path, including package name.
If the package encryption level is EncryptSensitiveWithPassword or EncryptAllWithPassword, use the Decrypt option to provide the password. If no password is included, dtexec will prompt you for the password.
Optionally, provide additional command-line options.
Press Enter.
Optionally, view logging and reporting information before closing the Command Prompt window. The Execute Package Utility dialog box opens.
In the Execute Package Utility dialog box, click Execute Package. Wait until the package has executed successfully.
In SQL Server Management Studio, in Object Explorer, you can connect to an SSIS server, expand the Stored Packages folder, and then expand either the File System or MSDB folder.
In SQL Server Management Studio, right-click a package, and then click Run Package.
Execute Package Utility opens.
Execute the package as described previously.
You can extend the enterprise capabilities of SSIS by using the Execute Package and Execute Process tasks.
The Execute Package task enables packages to run other packages as part of a workflow. You can use the Execute Package task for the following general purposes:
Breaking down complex package workflow
Reusing parts of packages
Grouping work units
Controlling package security
For example, you can use the Execute Package task to modularize your packages. Each child package can perform a small, well-defined unit of work, and then a parent package can contain multiple Execute Package tasks to execute all of the child packages. One common use is to have one package per data warehouse dimension and then have a parent package that executes all of the dimension packages.
A child package can be executed by a parent package, using an Execute Package task. The child package can use a configuration to read the parent package variables.
The Execute Process task can execute any file that can be executed from the command prompt. This includes the SSIS Command Line Utility (DTExec). You can specify the executable and command-line arguments. You can also execute a *.bat or *.cmd file that contains a dtexec command.
SQL Server Agent is a Windows service that executes scheduled administration tasks, which are called jobs. It uses SQL Server to store job information. Jobs contain one or more job steps. Each step contains its own task, for example, backing up a database. SQL Server Agent can run a job on a schedule, in response to a specific event, or on demand.
SQL Server Agent can be configured to execute an SSIS package. It can also be configured to modify the package XML configuration files, connection manager strings, variables, and other package properties.
In BIDS, in Solution Explorer, double-click NewProducts.dtsx to open the package designer.
On the Control Flow tab, right-click Execute SQL Task - Clear Product Names, and then click Execute Task.
In SQL Server Management Studio, in the QuickStartODS database, click the Table - dbo.ProductNames tab, and then, on the Query Designer toolbar, click the exclamation mark (!) (Execute SQL).
Verify that the QuickStartODS database ProductNames table is empty.
In BIDS, on the Debug menu, click Stop Debugging.
Right-click Sequence Container - File Doesn't Exist, and then click Execute Container.
In SQL Server Management Studio, click the Table - dbo.ProductNames tab, and then click the exclamation mark (!) (Execute SQL).
Verify that the QuickStartODS database ProductNames table now contains data.
In BIDS, on the Debug menu, click Stop Debugging.
On the Control Flow tab, right-click Foreach Loop Container - FuzzyInput Files, and then click Disable.
In Solution Explorer, right-click NewProducts.dtsx, and then click Execute Package. Wait until the package has executed successfully. Your screen should resemble this:
In SQL Server Management Studio, in Object Explorer, expand QuickStartODS, expand the Tables folder, right-click dbo.MatchedNames, and then click Open Table.
Notice that the tab in the middle of the screen changes to read dbo.MatchedNames.
Click the Table - dbo.MatchedNames tab, and then click the exclamation mark (!) (Execute SQL).
On the Table - dbo.MatchedNames tab, verify that the table is empty.
In BIDS, on the Debug menu, click Stop Debugging.
On the File menu, click Save All.
Close the NewProducts.dtsx package.
In this procedure, you'll learn how to use the Execute Package Utility.
In Windows Explorer, navigate to C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\XPkgUNewProducts.dtsConfig.
Right-click XPkgUNewProducts.dtsConfig, click Open With, and then click Microsoft Visual Studio Version Selector.
In BIDS, on the XPkgUNewProducts.dtsConfig tab, between the <ConfiguredValue> tags, notice that the name of the destination file has been changed to XPkgUProductsDestination.txt.
In Windows Explorer, double-click the C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\NewProducts.dtsx file. Execute Package Utility opens.
In Execute Package Utility, in the left pane, click Configurations, and then click Add. The Open dialog box appears.
In the Open dialog box, browse to C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\XPkgUNewProducts.dtsConfig, and then click Open.
In the Execute Package Utility dialog box, in the left pane, click each option to see the changes that can be made to a package when it is executed using Execute Package Utility.
Click Execute. The Package Execution Progress dialog box opens. This dialog box shows event log entries as the package executes.
When package execution completes, click Close to close the Package Execution Progress dialog box.
Leave the Execute Package Utility dialog box open.
In Windows Explorer, verify that the NewProducts package created the C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\Data\XPkgUProductsDestination.txt file.
In the Execute Package Utility dialog box, in the left pane, click Command Line.
Copy all of the text in the Command Line box.
In Windows Explorer, right-click C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\ExecuteNewProducts.cmd, and then click Edit.
In ExecuteNewProducts.cmd - Notepad, replace <paste here> with the text you copied from the Command Line box.
On the File menu, click Save.
Close the file, and then close Execute Package Utility.
In Windows Explorer, double-click C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\ExecuteNewProducts.cmd.
The command-line utility executes the NewProducts package.
When package execution completes, press any key to close the command-line window.
In SQL Server Management Studio, verify that you are connected to the SQL Server database engine. (If you are not connected, on the File menu, click Connect Object Explorer, and then, in the Connect to Server box, click Connect.)
In the left pane, toward the bottom of the tree, right-click the SQL Server Agent folder, and then click Start.
Note | By default, the SQL Server Agent service is stopped. To start the service, in Object Explorer, right-click the SQL Server Agent folder, and then click Start. |
Right-click the Jobs folder (located under the SQL Server Agent folder), and then click New Job. The New Job dialog box opens.
In the New Job dialog box, in the left pane, click General, and then, in the Name text box, type ExecutePackageJob.
In the left pane, click Steps, and then click New. The New Job Step dialog box opens.
In the New Job Step dialog box, in the Step Name text box, type ExecutePackageStep.
In the Type drop-down list, select SQL Server Integration Services Package.
In the Package Source drop-down list, select File System.
In the Package text box, navigate to C:\Documents and Settings\<username>\My Documents\Microsoft Press\is2005sbs\Chap08\NewProducts.dtsx, and then click Open.
Click OK to close the New Job Step dialog box, and then click OK to close the New Job dialog box.
In SQL Server Management Studio, in the left pane, expand the Jobs folder, right-click ExecutePackageJob, and then click Start Job At Step. SQL Server Agent executes the NewProducts package.
After the package executes, click Close to close the Start Jobs dialog box.
Now that the SQL Server Agent job is created, the package can be executed on a periodic basis by using the scheduling features in SQL Server Agent.