Sunday, July 31, 2011

Load Your Files Throug For Each Loop Container

In SQL Server 2000 Data transformation Services (DTS) it was a bit of a hack to be able to loop over files of a given type in a certain directory and import them into your destination. It involved a lot of "Glue Code" and a certain amount of fooling the package into going back to a previous task because it still had work to do. Well thankfully in SQL Server 2005 Integration Services (SSIS) that has all changed and this article is going to show you how.
The image below shows us how incredibly simple and clean the package will look when finished. There are some things worth pointing out at this stage. In the centre of the screen we see the Foreach Enumerator container and inside that we see the Data Flow task which houses the pipeline. At the bottom in the Connection Managers tray we see our Flat File Connection Manager (My Source File) and our OLEDB Connection Manager (My Destination). The Flat File Connection Manager is the one in which we are most interested for this article. Both of these managers are used in the Data Flow behind the DataFlow task. We will not be detailing the pipeline behind the DataFlow task in this article but it consists of a Flat File Source moving data to an OLEDB destination.

ThePackage

Let's begin then by opening up the Foreach enumerator and moving straight to the Collection node in the tree on our left. Below we see our information already populated.
Collection


What we see on the screen is pretty self explanatory but let's go through it anyway. We have chosen to enumerate over a file collection and ths is indicated by the value next to the Enumerator property at the top. We need to specify a folder over which to loop and for which type of files to look and we do that in the centre of the form. We are given three options as to what is returned when the loop finds a file in the folder at the bottom of the form. We can return the whole filename including extension and path, the name and extension or simply the name of the file found. Because our connection manager is going to need to know exactly where to find the file and it's name we have hosen the first option. The final thing we see on this screen is the ability to traverse subfolders. In our example we do not need to do this.
When the Foreach enumerator finds a file it needs to tell us about what it found and it does this by populating a variable. Click on to the Variable Mappings node now. Our package currently has no variables able to accept the name of the file so we are going to create a new one.
VarMapping

The next screen we see allows us to set the values of the variable. As we can see variables can be scoped in SSIS to certain executables in the package or to the package itself.
Scoped

Here is how our variable looks with all its properties set.


FileFound

Because the enumerator will only return us at most one value on every iteration we map our variable to an index of 0.
Mapped

We have
now configured everything as far as the Foreach enumerator is concerned. We now need to set the rpoerties of the Flat File Connection Manager. Highlight the manager in the tray at the bottom, right click and choose properties.

FilePropBefore

The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column drop the list down and choose ConnectionString

Ex1

Now hit the ellpises button to the right and we are taken through to the expression editor where we will build the actual expression itself.

Ex2

Our requirements are pretty simple here and all we want to do is to retrieve the variable we defined earlier. To do this simply drag the variable from the list at the top to the expression text box at the bottom. Property Expressions can become very complex and we shall no dount be seeing more of them in future articles. After you have chosen the variable click OK
 
Ex3

We now see that our expression is mapped to our ConnectionString property. Click OK
Finally we can now see our File Manager's Connection string property being mapped to an expression in the properties of the manager.
FilePropAfter

That's all there is to it. When the enumerator finds a file matching our requirements it will set the correct property on the connection manager and this will be used by the pipeline at runtime.

Friday, July 29, 2011

Security for SSIS packages



Protection for SSIS packages:
You set the protection level of a SQL Server 2005 Integration Services (SSIS) package when you first develop it in Business Intelligence Development Studio. Later, when the package is deployed, imported or exported from Integration Services in SQL Server Management Studio, or copied from Business Intelligence Development Studio to SQL Server, the SSIS Package Store, or the file system service, you can update the package protection level. For example, if you create and save packages on your computers with one of the user key protection level options, you likely would want to change the protection level when you give the package to other users; otherwise they cannot open the package.
The following table describes the protection levels that Integration Services provides. The values in parenthesis are values from the DTSProtectionLevel. These values appear in the Properties window that you use to configure the properties of the package object when you work with packages in Business Intelligence Development Studio.
Protection level
Description
Do not save sensitive (DontSaveSensitive)
suppress sensitive information in the package when it is saved. This protection level does not encrypt, but instead it prevents properties that are marked sensitive from being saved with the package and therefore makes the sensitive data unavailable to other users. If a different user opens the package, the sensitive information is replaced with blanks and the user must provide the sensitive information.
Encrypt all with password (EncryptAllWithPassword)
Encrypts the whole package by using a password. The package is encrypted by using a password that the user supplies when the package is created or exported. To open the package in SSIS Designer or run the package by using the dtexec command prompt utility, the user must provide the package password. Without the password the user cannot access or run the package.
Encrypt all with user key (EncryptAllWithUserKey)
Encrypts the whole package by using a key based on the user profile. Only the same user using the same profile can load the package. The package is encrypted by using a key that is based on the user who created or exported the package. Only the user who created or exported the package can open the package in SSIS Designer or run the package by using the dtexec command prompt utility.
Encrypt sensitive with password (EncryptSensitiveWithPassword)
Encrypts only the sensitive information in the package by using a password. DPAPI is used for this encryption. Sensitive data is saved as a part of the package, but that data is encrypted by using a password that the current user supplies when the package is created or exported. To open the package in SSIS Designer, the user must provide the package password. If the password is not provided, the package opens without the sensitive data and the current user must provide new values for sensitive data. If the user tries to execute the package without providing the password, package execution fails. For more information about passwords and command line execution, see dtexec Utility.
Encrypt sensitive with user key (EncryptSensitiveWithUserKey)
Encrypts only the sensitive information in the package by using keys based on the current user. Only the same user using the same profile can load the package. If a different user opens the package, the sensitive information is replaced with blanks and the current user must provide new values for the sensitive data. If the user attempts to execute the package, package execution fails. DPAPI is used for this encryption.
Rely on server storage for encryption (ServerStorage)
Protects the whole package using SQL Server database roles. This option is supported only when a package is saved to the SQL Server msdb database. It is not supported when a package is saved to the file system from Business Intelligence Development Studio.
 
The package protection levels that encrypt packages using passwords require that you provide a password also. If you change the protection level from a level that does not use a password to one that does, you will be prompted for a password.
Encryption, as used by package protection levels, is performed by using the Microsoft Data Protection API (DPAPI), which is part of the Cryptography API (Crypto API).
Integration Services uses the Triple DES cipher algorithm with a key length of 192 bits, available in the .NET Framework Class Library (FCL), for the protection levels that use a password.





Thursday, July 28, 2011

SSIS interview questions

1)difference between control flow and data flow?

2)logging in ssis?

3)how can we use check points in SSIS packages?

4)what is transaction concept in SSIS?

5)Error Handling in ssis?

6)how can we deploy the packages in SSIS?

7)in how many ways we can run the packages in SSIS?

8)what are all the command line tools available in SSIS?

 9)How do you schedule ssis packages ?

10)how do we run the stored procedures in SSIS?

11)explain SCD and its types?

12)Difference between SSIS and DTS?

13)Have you used SSIS Framework?

14)What configuration options have you used?

15)How to quickly load data into sql server table?

16)What is XMLify component?

17) You would like to log all the package errors to a custom database table you have created for auditing purposes. How can you accomplish this task?

18) Explain architecture of SSIS?

19) What is Execution Tree?

20) Difference between Unionall and Merge Join?