Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS how to set connection string dynamically from a config file

I am using SQL Server Integration Services (SSIS) in SQL Server Business Intelligent Development Studio.

I need to do a task that is as follows. I have to read from a source database and put it into a destination flat file. But at the same time the source database should be configurable.

That means in the OLEDB Connection Manager, the connection string should change dynamically. This connection string should be taken from a configuration/XML/flat file.

I read that I can use variables and expressions to change the connection string dynamically. But how do I read the connection string value from a config/XML/flat file and set the variable?

This part I am unable to do. Is this the right way to achieve this? Can we add web.config files to an SSIS project?

like image 861
SNA Avatar asked Mar 23 '10 05:03

SNA


People also ask

How do you change the connection string in SSIS package dynamically?

Copy the text in the ConnectionString property. Click on the build symbol to the right of the Expressions property. Choose the ConnectionString property from the list, and click on the build button to set the expression for this. Paste your connection string into the box.

How do I change the connection manager value at runtime in SSIS?

The idea is to pass the value of the connection (Connection1 or Connection2) you want to use when calling this proc. Then create another variable in the SSIS using the following Conditions and use the variable to parameterize your connection manager.


1 Answers

First add a variable to your SSIS package (Package Scope) - I used FileName, OleRootFilePath, OleProperties, OleProvider. The type for each variable is "string". Then I create a Configuration file (Select each variable - value) - populate the values in the configuration file - Eg: for OleProperties - Microsoft.ACE.OLEDB.12.0; for OleProperties - Excel 8.0;HDR=, OleRootFilePath - Your Excel file path, FileName - FileName

In the Connection manager - I then set the Properties-> Expressions-> Connection string expression dynamically eg:

 "Provider=" + @[User::OleProvider] + "Data Source=" + @[User::OleRootFilePath] + @[User::FileName]  + ";Extended Properties=\"" + @[User::OleProperties] + "NO \""+";" 

This way once you set the variables values and change it in your configuration file - the connection string will change dynamically - this helps especially in moving from development to production environments.

like image 136
Lekha Mathew Avatar answered Sep 21 '22 15:09

Lekha Mathew