Wednesday, August 26, 2015

Retrieve information from the System.Object result set in a SSIS package.

Populate a package variable with a result set using Execute SQL Task.

Write a SQL query, set the ResultSet property to Full result set and configure a package variable in the Result Set property window.The package variable’s type is System.Object.

Following code in a script task retrieves the number of records in the result set.

System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();
            DataTable dt = new DataTable();
            da.Fill(dt, Dts.Variables["User::JobTitles"].Value);
            MessageBox.Show(dt.Rows.ToString());

Tuesday, August 25, 2015

List of SSIS Error Messages

Integration Services Error and Message Reference
https://msdn.microsoft.com/en-us/library/ms345164.aspx

Error Message:
Solution file cannot be converted because it cannot be modified.To convert the solution,change the permissions
on the solution file to allow modification and re-open it.
Solution:
Make sure the sln solution file is not marked as read only.

Error Message:
[Lookup [11]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "Lookup" failed because error code 0xC020901E occurred, and the error row disposition on "Lookup.Outputs[Lookup Match Output]" specifies failure on error. An error occurred on the specified object of the specified component.There may be error messages posted before this with more information about the failure.
Solution:
Change specify how to handle rows with no matching entries to Ridirect rows to no match output.The default is fail component.
Two things to be noted here, Even though values are same in both table, if the data type is different (char in 1st table and varchar in 2nd table) error will be thrown saying that no match.
In lookup properties set validate metadata to false. Because it is validating metadata as well. This should be done if you are so sure that both table structure is sync.

Error Message:
[Bulk Insert Task] Error: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.Bulk load: An unexpected end of file was encountered in the data file."
Solution:
This error was due to Format issue with source datasource text file. I did not specify correct delimiter in Bulk Insert Task component. So, do check that also

Error Message:
Validation error. Data Flow Task: Data Flow Task: There is more than one data source column with the name "1".  The data source column names must be unique.   Package1.dtsx
Solution:
Delete all data from flat file and run the ssis package.

Error Message:
SSIS Flat File Source Error: 0xC020200E Cannot open the datafile and 0xC004701A failed the pre-execute phase
Solution:
http://www.roelvanlisdonk.nl/?p=1441

Error Message:
File System Task Error: An error occurred with the following error message: "Empty file name is not legal.
Parameter name: sourceFileName".
Solution:
There is a File system task which need to pass a Dest file name or Source fie name as parameter into this task.
Now it seems it doesn't pass/input the parameter so that the program throws this Exception.

Error Message:
Failed to execute the package or element. Build errors were encountered. For more information, see the Output window.
Solution :
Close all other applications which are using current source in dataflow and try again.
If it doesn't  work right click on project and create build.It will show some errors which should be resolved.

Error Message:
Project consistency check failed. The following inconsistencies were detected: Package.dtsx has a different ProtectionLevel than the project.
Solution :
These steps got it fixed:
Open your project in Visual Studio (2012).
Right Click your project name in Solution Explorer to the right of the screen and select Properties
Change ProtectionLevel under Security to DontSaveSensitive
Double click a package and under Properties, there should be a list with properties. Change ProtectionLevel under Security to DontSaveSensitive in the Properties (do this for all packages)
Save all Close Visual Studio (2012)
Then go to C:\ProjectName\ProjectName\ And search for the file with .dtproj extension. The one with the type Integration Services Project File and not the one with the type Visual Studio Project User Options File.
Open ProjectName.dtproj with a text editor. I used notepad++, but you can also open it using Visual Studio, and other text editors.
Search for and change EncryptSensitiveWithUserKey to DontSaveSensitive.
Search for and change any number behind this to 0 zero. Search the entire file, there should be more than one if you have more packages than one.
Save the file, close it, go into Visual Studio (2012) and Right Click on the project name in Solution Explorer and click build. Everything should work now

Thursday, August 20, 2015

SSIS Interview Questions & Answers

1. What is the SQL Server Import and Export Wizard?
The Import and Export Wizard is a utility that provides a simplified interface
for developing data movement operations where data is extracted from a
source and loaded into a destination, without any transformations.
Import and Export Wizard is mainly used for simple Data Movement Operations.

2.What is SSDT?
SQL Server Data Tools (SSDT) is a special edition of Visual Studio used for developing
SQL Server 2012 solutions, such as SSIS packages, SSAS multi-dimensional
models, and SSRS reports

3. What is a control flow?
In SSIS packages, the control flow defines the tasks used in performing data
management operations; it determines the order in which these tasks are executed
and the conditions of their execution.

4. What is a data flow?
In SSIS packages, the data flow is a special control flow task used specifically in
data movement operations and data transformations.

5.What is a container and how many types of containers are there?
1.Sequence Container
2.For Loop Container
3.For Each Loop Container

For Loop Container
This container executes the encapsulated tasks continously, based on an
expression.The looping continues while the result of the expression is
true.
For Each Loop Container
This container executes the encapsulated tasks continously, per each item
of the selected enumerator.for example files in a folder.
Sequence Container
This container has no programmatic logic It groups the related tasks to form a logical unit.

6.What are variables and what is variable scope?
Variables are used to store values that SSIS executables can access at runtime.This object contains a value that can be hardcoded,
dynamically set, or modified multiple times throughout the execution of the package.
Principally, variables provide a method for objects in a package to communicate with each other.

Variables can be scoped at the package, container, task or event handler level.

7.What is a breakpoint in SSIS?
Breakpoints are used to debug the SSIS Package in design time.It allows you to stop the execution of a package to investigate and troubleshoot the state of the SSIS package.
To set a breakpoint, right-click the task or container you want to observe, and select
Edit Breakpoints to open the Set Breakpoints dialog box. In the Set Breakpoints dialog box,
you can enable breakpoints on the listed conditions.

There are ten events in the Control Flow
OnPreExecute: Called when a task is about to execute.This event is raised by a task or a container immediately before it runs.
OnPostExecute: Called immediately after the execution logic of the task finishes. This event is raised by a task or container immediately after it runs.
OnError: Called by a task or container when an error occurs.
OnWarning: Called when the task is in a state that does not justify an error, but does warrant a warning.
OnInformation: Called when the task is required to provide information.
OnTaskFailed: Called by the task host when it fails.
OnProgress: Called to update progress about task execution.
OnQueryCancel: Called at any time in task processing when you can cancel execution.
OnVariableValueChanged: Called by the Integration Services runtime when the value of a variable changes. The RaiseChangeEvent of the variable must be set to true to raise this event.
OnCustomEvent: Called by tasks to raise custom task-defined events.



Friday, June 5, 2015

MSBI Interview questions & answers Part 2

  1. Tell me about yourself?
  2. Tell me the current project you are working? and type of your current project?
  3. How much you are efficient in sql server,ssis and ssrs?
  4. What is the difference between delete and truncate?
  5. What is the difference between function and stored procedure?
  6. What is the difference between temp table and table variable?
  7. What is the difference between control flow and data flow?
  8. What is merge join?
  9. What are the tasks you used in data flow?
  10. Types of joins?
  11. What is – DML, DDL, DCL and TCL?
Notes:
  • Function Cannot perform permanent environmental changes to SQL Server (i.e. no INSERT or UPDATE statements allowed).
  • A Function can be used inline in SQL Statements but stored procedure cannot.
  • We can't use transactions in UDF.
  • SP can have input\output parameter.Function can have only input parameter.
  • We can use exception handling using Try-catch block in SP.We can't use Try-Catch block in UDF.
  • Temporary tables cannot be used in User defined function.Stored procedure can use Temporary tables.
  • User defined functions cannot execute Dynamic SQL.Stored procedure can execute Dynamic SQL.

  • Temporary Tables are same as real tables so you can do things like CREATE INDEXes, etc We can create non – clustered index on temporary table. We cannot create a non-clustered index on table variable.If we have large amount of data and performing queries on it then temporary table may be better option than table variable since we can increase the performance of a query.Table variables can have indexes by using PRIMARY KEY or UNIQUE constraints.
  • Table variables don't participate in transactions, logging or locking.
  • You can create a temp table using SELECT INTO, which can be quicker to write 
  • Both table variables and temp tables are stored in tempdb.
  • Global Temp Tables (##tmp) are another type of temp table available to all sessions and users.
  • We can pass the table variables as a parameter of stored procedures or functions.
  • Scope of temporary table is session.Scope of table variable is batch.

  • In SSIS packages, the control flow defines the tasks used in performing data management operations; it determines the order in which these tasks are executed and the conditions of their execution.
  • In SSIS packages, the data flow is a special control flow task used specifically in data movement operations and data transformations.

  • INNER JOIN : This join returns rows when there is at least one match in both the tables.
  • OUTER JOIN : There are three different Outer Join methods.
  • LEFT OUTER JOIN : This join returns all the rows from the left table with the matching rows from the right table. If there are no columns matching in the right table, it returns NULL values.
  • RIGHT OUTER JOIN : This join returns all the rows from the right table with the matching rows from the left table. If there are no columns matching in the left table, it returns NULL values.
  • FULL OUTER JOIN : This join combines left outer join and right outer join. It returns row from either table when the conditions are met and returns null value when there is no match.
  • CROSS JOIN : This join is a Cartesian join that does not necessitate any condition to join. The resultset contains records that are multiplication of record number from both the tables.

  • DML : Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.Examples: SELECT, UPDATE, INSERT statements
  • DDL : Data Definition Language. It is used to create and modify the structure of database objects in database.Examples: CREATE, ALTER, DROP statements
  • DCL : Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.Examples: GRANT, REVOKE statements
  • TCL : Transactional Control Language. It is used to manage different transactions occurring within a database.Examples: COMMIT, ROLLBACK statements


  • The Merge Join joins two sorted datasets using a FULL, LEFT, or INNER join. For example, you can use a LEFT join to join a table that includes product information with a table that lists the country/region in which a product was manufactured.The result is a table that lists all products and their country/region of origin.
  • Requirements:The Merge Join Transformation requires sorted data for its inputs.The Merge Join transformation requires that the joined columns have matching metadata. For example, you cannot join a column that has a numeric data type with a column that has a character data type. If the data has a string data type, the length of the column in the second input must be less than or equal to the length of the column in the first input with which it is merged.

Thursday, June 4, 2015

MSBI Interview Questions & Answers Part 1

  1. Why SSIS? What is the use of ETL?
  2. What is difference between SSIS and SSAS?
  3. Diference between union all and merge transformation?
  4. What is difference between Multicast and Conditional Split?
  5. What are the performance issues you have faced in SSIS?
  6. What is a cross apply and how to use this?
  7. What is CTE?Can we use more than one CTE in a single select query?
  8. what is control flow and dataflow?
  9. What is the difference between drilldown and drill through report?
  10. How to implement type 2 SCD using SSIS and queries?
Notes : 
A drill through report allows you to go from summary to detail.
A drill down reports allows you to look to the data in different levels.

Slowly Changing Dimension in ssis support
Fixed Attribute
Select this type when the values in a column should not change.Changes are treated as errors.
Changing Attribute
Select this type when changed values should overwrite existing values.This is a Type 1 change.
Historical Attribute
Select this type when changes in column values are saved in new records.Previous values are saved in a records marked as outdated.This is a Type 2 change.

Monday, June 1, 2015

Variables,Parameters and Expressions


SSIS includes multiple objects that can be used to create dynamic packages.SSIS can dynamically set a property in a task or component using an expression, which can be built using a set of building blocks, including variables,parameters,functions, literals, and more.






















Variables

Variables are used to store values that SSIS executables can access at runtime.
This object contains a value that can be hardcoded, dynamically set once, or modifi ed multiple times throughout the execution of the package. Principally, variables provide a method for objects in a package to communicate with each other.

You can use variables in SSIS in the following places:
  • Setting up any connection string
  • Setting up row count transform in the data flow task
  • Used in For Each Loop, For Loop, Parameter mapping in Execute SQL Task.
  • Script task

Parameters

Parameters are a new feature introduced in SQL Server 2012.
SSIS uses two types of parameters: project parameters and package parameters. Project parameters are created at the project level and can be used in all packages that are included in that project.On the other hand, package parameters are created at the package level and can be used only in that package.

Package-level parameters are extremely useful for the parent-child package design. They allow you to pass specific values between the parent packages in order to configure the child packages.When using the project deployment model, parameters are the best choices to replace package confi gurations to create a dynamic and more flexible SSIS solution.

Expressions

Expressions are used in SSIS to return a value based on the evaluation of criteria. The expression

language itself consists of identifiers, literals, functions, and operators. Some expressions can be written to assign values to variables, return the value of a calculation, or be used as conditional statements. 

Variables and parameter difference

1.Execution
The value of a parameter can’t change within the execution of a package.That means, its value remains the same for the entire execution of the package.

The value of variables can change during the execution of the package

2.Scope
Parameters can be defined at 2 different levels:
Project. These type of parameters are available to all packages within the SSIS project. 
Package. These type of parameters are available only the package on which they were defined.

Variables can be scoped at the package, container, task or event handler level.

Saturday, May 30, 2015

Implement transactions in SSIS.

  • You can set package transactions at the entire package level or at any control flow container level or task level.
  • Transactions in SSIS use the Microsoft Distributed Transaction Coordinator(MSDTC); the MSDTC service needs to be started on the computer for transactions to work. 
  • To enable a transaction within a package, you need to set the TransactionOption property of the task or container to Required. The TransactionOption property exists at the package level and at the container level, as well as for almost any control flow task. 

It can be set to one of the following:
  • Required : If a transaction already exists, join it; if not, start a new transaction.
  • Supported : If a transaction exists, join it (this is the default setting).
  • NotSupported : The package, container, or task should not join an existing transaction.

If a series of tasks must be completed as a single unit in which either all the tasks are successful and committed or an error occurs and none of the tasks are committed,place the tasks within a sequence container and set the TransactionOption property of the container to Required.

Create the simple package.


























This package is quite basic in that all it does is insert some data into the table
and then the last task will deliberately fail. Open SSMS and run the following code.

CREATE TABLE Transaction_test
(
id int
)

In the first task, insert some data into the table you just created with the following code:

Insert into Transaction_test(id) values (1)

To make the final task fail at runtime, enter the following code:

Insert into Transaction_test(id) values ("A")

Run the package with no transactions in place and see what happens.

























The first task succeeds, and the second fails.If you go to your database, you should see data inserted.





















Now run the following code in SSMS to delete the data from the table:

Truncate table Transaction_test

Next, you want to set up the package to start a transaction that the tasks can join.You do that by
setting the properties of the package.Set the TransactionOption property to Required.



You now need to tell the tasks in the package to join this transaction, by setting their
TransactionOption properties to Supported.



























Now when you re-execute the package, a DTC transaction will be started by the package, all the
tasks will join, and because of the failure in the last task, the work in the package will be undone.
Go back to SSMS and query the table. You should see no data in it.

Tuesday, May 26, 2015

Deploying SSIS Packages

SQL Server 2012 Integration Services introduces a new approach for deploying SSIS projects, known as Project Deployment Model.

The project deployment model allows each SSIS project to be treated as a single unit, to be configured and deployed as a whole. A project can contain one or more packages, one or more parameters, and one or more connection managers.Under the project deployment model all of these are deployed to the destination SSIS server as a single unit.

Deployed SSIS projects are stored in the SSISDB catalog.The SSISDB catalog is used to store SSIS project and package definitions, as well as other SSIS metadata.

The key features of this new deployment model are the Integration Services catalog, environments, and parameters. The new deployment model is designed to make deployment and administration of SSIS packages and ETL systems easier across multiple environments.

In SQL Server 2005, 2008 you would deploy packages into SQL Server’s msdb database or to the filesystem. Now, in SQL Server 2012’s project deployment model, you deploy to the SSIS catalog.

An SSIS package created in an earlier version of SQL Server cannot be deployed directly to the SSIS server; it first needs to be converted by the SQL Server Integration Services Project Conversion Wizard to compile it into a deployment file, which can then be deployed to the SSISDB catalog.

Setting the SSIS Catalog

When you first install Integration Services, the SSIS catalog will need to be created. Create it manually by right-clicking on the Integration Services folder in the Database Engine in SSMS and selecting Create Catalog.




















A create catalog wizard,  guides you through the process of creating the catalog.you must also have the Common Language Runtime (CLR) integration turned on by checking the Enable CLR box.The default name of the database is SSISDB and cannot be renamed.The Create Catalog prompt will ask for a password. This password creates a database master key, and the master key encrypts sensitive data in the catalog.Click OK to create the database and catalog.
  • Enable CLR Integration  -  Checked
  • Enable Automatic Execution Of Integration Services Stored Procedure At SQL Server Startup  - Unchecked
  • Name Of The Catalog Database  -  SSISDB
  • Password  - Provide your password.











Saturday, May 23, 2015

New in SQL Server Integration Services 2012

1.Data Taps
Data taps are a new feature in SQL Server 2012 for troubleshooting package execution. You can capture a copy of the data from a specific data path in your data flow tasks in a comma-delimited file at run time.Much like data viewers in design time.Data taps enable you to analyze data in a production environment.For more info

2.New Shared Connection Managers
In prior versions of SSIS, connection managers were scoped to individual packages, not projects. An SSIS project did not allow shared connections across packages inside the project.
This release allows you to create connection managers at the project level that can shared by multiple packages in the project. The connection manager you create at the project level is automatically visible in the Connection Managers tab of the SSIS Designer window for all packages.

3.SSIS Parameters at the Project, Package, and Task Level
Integration Services (SSIS) parameters allow you to assign values to properties within packages at the time of package execution. You can create project parameters at the project level and package parameters at the package level. 

4.UNDO Feature.
In SQL Server Integration services 2012, you can undo and redo up to 20 actions in the SSIS Designer.Undo and redo is not possible in prior versions of SSIS.

5.Support for ODBC Data Sources and Destinations.
This is a new component in SSIS 2012.This connects to a defined ODBC source/destination by using native ODBC.In previous versions we use OdbcDataProvider in ADO.NET.

6.New Deployment Feature
Project Deployment model is the new deployment model in SSIS 2012.Which uses its own designated database called SSISDB.In package deployment model a package is the single unit but in project deployment model deploy the whole project to the SSIS catalog, 

7.New Management Dashboard Feature
This report shows activity on the package execution.

Sunday, May 17, 2015

Implementing SSIS Environment Variables

Step 1 : Create Parameters in SSDT

Parameters can be defined at the package level and at the project level. Package-level parameters are visible only to tasks and components within that package. Package parameters are defined in the $Package namespace. Parameters defined at the project level are global—all packages within the project are able to make use of them. Project parameters are defined in the $Project namespace.

In this example i have created two package level parameters and marked as required,as shown in the below image.









Parameters that are marked as Required must have their values specified at runtime. 
Required parameters will not use the design time value when the package runs—a new value must be specified by the caller 
If a parameter's required property is set to false,its design time value will be used if no other value is supplied in run time.

If a parameter is marked as Sensitive, its value will be stored in an encrypted format within the package


Step 2: Parameterize Initial catalog.

In this example i have parameterized the Initial catalog.




























You can also configure Connection string,user name,server name etc













I set the parameter to be Required ,must specify their values at runtime.

After parameterizing the connection manager, save the SSIS solution, and then open
the Parameters tab of the SSIS package pane.You can see the above created parameter in the parameter tab.



Step 3: Deploying Packages to the Package Catalog

Now let’s deploy the project to our SQL Server instance.
The Deployment Wizard is the easiest way to deploy packages to the catalog. You can access
the wizard through SSDT by right-clicking a project and selecting Deploy. 





















After finishing the deployment you can see the deployed project under SSIS DB catalog.












  











Step 4: Create Environments and add variables to it.

Environments allow you to set values to all parameters within projects through their variables at runtime. These environment variables can also be used to configure connection managers so that data can be sourced and loaded according to the simulation you need to run.

To create an environment, navigate to the Environments subfolder where you deployed your project. Right-click the subfolder and select Create Environment.  
I created two environments 'Dev' and 'Prod'



























After creating the environment, you can add variables to it.



























You can also copy the name and value for each parameter from the SSDT parameters window into the environment variable window.























The environment variables can be mapped to the different project and package parameters that are defined.
For this navigating to the project in the Integration Services catalog.
right clicking it,and selecting Configure.


























This page allows you to define the different environments that can pass values to
the project during execution.
Add environments in environment reference tab.

























After the environment reference is set up, you can map project parameter to variables within the environment. 
























Parameters tab allows you to map values of all the parameters contained within the project to the environment variables values. 



Tuesday, May 12, 2015

Data Warehouse vs Data Mart

Typical data warehouses have these characteristics:
  • Holds multiple subject areas
  • Holds very detailed information
  • Works to integrate all data sources
  • Does not necessarily use a dimensional model but feeds dimensional models.

The data mart is a subset of the data warehouse which is usually oriented to a specific business line or team (Finance has their data mart, marketing has theirs, sales has theirs and so on).

Wednesday, May 6, 2015

SSIS Topics

Server Modes of an Analysis Services Instance

Analysis Services can be installed in one of three server modes:
  • Multidimensional and Data Mining (default)
  • PowerPivot for SharePoint
  • Tabular. 
The easiest way to determine the server mode of Analysis Services instance of SQL Server 2012 is to connect to the server in SQL Server Management Studio and note the icon next to the server name in Object Explorer.














The server mode of an Analysis Services instance is determined during setup when you choose options for installing the server.

Tuesday, May 5, 2015

Data taps in SSIS

  • Data taps are a new feature in SQL Server 2012 for troubleshooting package execution. 
  • You can capture a copy of the data from a specific data path in your data flow tasks in a comma-delimited file at run time.
  • Much like data viewers in design time.
  • Data taps enable you to analyze data in a production environment.

Information needed for Data tap


Folder Name : The Name of the folder in SSIS server.


Project Name : The name of the SSIS project that holds the package

Package Name : The package name.





















Data Flow Path ID : The value of the IdentificationString property of the data flow path.







Data flow task path : The path of the data flow task within the package.This can be read from the PackagePath property of the selected data flow task in SSDT.








































The data files will be created in installation drive.The path is 'C:\Program Files\Microsoft SQL Server\110\DTS\DataDumps'.
I have specified the data file name as output.csv










 









We need to execute three below stored procedures aganist SSISDB
1.catalog.create_execution
  Create an execution instance of a package.

2.catalog.add_data_tap
  Add a data tap.

3.catalog.start_execution
  Start the execution instance of the package.

Sample script

Declare @execid bigint

EXEC [SSISDB].[catalog].[create_execution]
@folder_name=N'Advance SSIS',
@project_name=N'Advanced SSIS',
@package_name=N'ForEachLoop Container.dtsx',
@execution_id=@execid OUTPUT

EXEC [SSISDB].[catalog].add_data_tap @execution_id = @execid,
@task_package_path = '\Package\Load Flat Files',
@dataflow_path_id_string = 'Paths[File Extract.Flat File Source Output]',
@data_filename = 'output.txt'

EXEC [SSISDB].[catalog].[start_execution] @execid





Foreach Loop Container in SSIS

Loops through a series of fi les or records in a data set, and then executes the tasks in the container for each record in the collection.

Enumerator
An enumerator specifies the collection of objects that the container will loop through.
The Foreach loop container supports the following enumerator.
1.Foreach File Enumerator : Performs an action for each file in a directory with a given file extension
2.Foreach Item Enumerator: Loops through a list of items that are set manually in the container
3.Foreach ADO Enumerator : Loops through a list of tables or rows in a table from an ADO recordset
4.Foreach ADO.NET Schema Rowset Enumerator : Loops through an ADO.NET schema
5.Foreach From Variable Enumerator : Loops through a SQL Server Integration Services (SSIS) variable
6.Foreach Nodelist Enumerator : Loops through a node list in an XML document
7.Foreach SMO Enumerator : Enumerates a list of SQL Management Objects (SMO)

Foreach Loop container commonly Used for executing a set of operations repeatedly based on an enumerable collection of items (such as files in a folder, a set of rows in a table, or an array of items).

TRY IT

Loop through a collection of flat files in a directory and load them to a SQL table

Configuration.
  • Specify the path of the files directory.
  • Specify what kind of file extension the file have.(eg. for text files '*.txt').
  • Create a variable 'FileName' to store the location of the file name while looping.
  • Use the above created variable as an expression for the  file connection manager that points to the flat file.
Because the flat files each have a different name, you can use the Variable
Mappings tab in Foreach loop editor to dynamically change a variable value for each iteration of the loop. That variable then can pass the correct file name to the Flat File Connection with an expression.

Steps :
1.Create a new package
2.Drag a Data Flow Task onto your designer
3.Create a new Flat File Connection Manager,and point it to the first file. Also, check the
Column names in the first data row option and go to the Columns page to ensure all the columns
are defined properly; then click OK.
4.In the Data Flow, bring a new Flat File Source. Open the Flat
File Source Editor by double-clicking the Flat File Source and make the connection manager
the newly created one. Then click OK.
5.Next, create an OLE DB Connection Manager, using the AdventureWorks2012 database.
6.Bring an OLE DB Destination in the Data Flow and connect the Data Flow path
from the source to it.
7.Drag a Foreach Loop Container.
8.Place the Data Flow Task inside the Foreach Loop Container; then open the Foreach Loop
Editor by double-clicking the top banner portion of the container. On the Collections tab,
select Foreach File Enumerator from the Enumerator property drop-down box. The Foreach
File Enumerator is the default when you open the editor.
9.Set the folder property.for bring back all text files in the directory set Files Property to *.txt.
10.Create a new variable.
11.in the variable mapping tab,select the variable name.
Each time the container runs the variable value will change to the current file.
12.The last step is to put an expression on the File Connection Manager that uses
the variable you just created inside the Foreach Loop Container. Select the connection managers and press F4 to bring up the Properties window. Click the ellipsis next to the Expressions property to open
the Property Expressions Editor. Select ConnectionString from the Property drop-down and
then click the ellipsis in the Expression box.
13.In the top left of the Expression Builder, expand the Variables and Parameters folder and
drag the variable down into the Expression box. If you try to click Evaluate
Expression now, there will be no result. Remember that this expression will be populated at
run time, so you will see nothing here yet.
14.The package is now complete.A succesful run will loop through all the files and load to the table.

Forloop container and Foreachloop conatainer
For Loop iterates through the content of the container a number of times you define or you define with an expression, whereas the Foreach Loop Container iterates for every member of the enumerator.If there are no members, the container will not execute.