Back to the Denali theme - today’s post is from Xiaochen Wu, a tester on the SSIS team based in Shanghai.
-------------------
In SSIS, we can manipulate packages programmatically with the SSIS object model. In Denali, we extended the object model to support the new concepts we introduced including project and parameter.
Project Object ModelIn Denali SSIS, we can create, load, modify and save projects dynamically with object model. Following is the code sample of how to manipulate projects programmatically:
//Update it to a valid file path. The “.ispac” is the extension of project fileWhen we create a new project, we can specify where we want to save this project as a parameter. The project storage can be a file (the full file name) or stream (System.IO.Stream). The storage will take effort when you save the project. We will talk about the details in next sections.
We can also load the project from a project file (.ispac) or stream. Please notice that if we load project from stream, we should first set the position within the stream to the beginning. If our project file or stream is protected or partially protected by password, we can also specify the password when load the project.
In Denali SSIS, there’re 3 ways to save the projects: Save(), SaveAs() and SaveTo().
If the project storage is already specified, we can use the Save function to save the project to the default storage. If the file or stream is not empty, the existing content will be overwritten. If we call the Save function before we specify the project storage, we will get exception.
The SaveAs function can save project to the specified storage and change to default project storage to the specified one.
The SaveTo function also can save project to the specified storage. But it will not change the current default project storage.
Following is the code sample of saving projects.
In Denali SSIS, we can add, get or remove packages in an existing project:
When we add packages to the project, we need to specify the package stream name which is a string ended with “.dtsx”. The stream name can identify a package within a project and it is not necessary to be the same with the package name in package properties.
Parameter is another new concept we introduced in Denali SSIS. We can use the object model to add, modify and remove the parameter for packages or projects.
When we add a parameter, we need to specify the parameter name and data type. The parameter name should be identical for a project or a package. But we can have a project parameter and a package parameter with the same name, because they can be distinguished by the namespace. The namespace of project parameter is “$Project” and namespace of package parameter is “$Package”.
In Denali SSIS, the following data types are not supported for parameters: Empty, Object, DBNull, Char and UInt16. And when we specify values of parameters, it should have the same data type with the parameter. For example, the following code will throw exception:
In the project or package, we can get the parameter by name or index and use it in the package as a variable. Following is the sample code of manipulating parameters:
If we want to protect our projects with password or user key, we need to specify the protection level and password of the project. When we add a package to project, the protection level and password of the package will be automatically updated to the same value with the corresponding project properties. And if we want to change it, we will get the exception.
In this article, we discussed how to use SSIS object model to manipulate projects and parameters. For more details, please refer to MSDN or SQL Server Book Online.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.