dfd
dfd

Reputation: 31

How to define connection string for multiple environments in SSIS?

Anyone have any idea how do we specify different connection strings in SSIS for different environments - like system integration test environment, user acceptance test environment and production environment?

Is it done by defining multiple connection managers or we can define multiple configuration files and point our connection string to?

Upvotes: 1

Views: 2758

Answers (1)

Anoop Verma
Anoop Verma

Reputation: 1505

You do not need to have multiple connections for the same database.

In SSIS 2008:

It's a good idea to have your connection strings defined using an expression. This is how you can do it:

Suppose you have added a anew OLEDB connection in your connection manager. Copy the value of the ConnectionString property. IT would look like this: Data Source=(local);Initial Catalog=Learn;Provider=SQLNCLI10.1;Integrated Security=SSPI;Application Name=SSIS-RaggedFile-{03053F2E-8101-4985-9F2B-8C2DDE510065}(local).Learn;Auto Translate=False;

Remove the non-essentials: Data Source=(local);Initial Catalog=Learn;Provider=SQLNCLI10.1;Integrated Security=SSPI;

Now create three new variables at the control surface level: sServer, sDb, sProvider. Type for all these three varaibles will be string. Their values - using this example - will be (local), Learn, and SQLNCLI10.1.

Go back to the ConnectionString property of your connection. and set its value to

"Data Source=(local);Initial Catalog=Learn;Provider=SQLNCLI10.1;Integrated Security=SSPI;" 

Now, replace the server, db, and provider with the variables you have created to make your expression look like this:

"Data Source=" + @[User::sServer] + ";Initial Catalog=" + @[User::sDb] + ";Provider=" + @[User::sProvider] + ";Integrated Security=SSPI;"

When we move from one environment to another, we may encounter different versions of the databases - hence it is helpful to have a variable for provider as well.

Now, these values can be changed at the time of deployment.

In SSIS 2012 - This method would still work with a little bit of change. Change these three variables to parameters and make them required. That way, at the time of deployment of deployment, you will be forced to change the values. This is just a starting point. Read up on server environment.

Note: I opine that a variable should have atomic value. This helps in avoiding any error due to mistyping. That's why I have created three separate variables as opposed to having one variable called sCnxn (for example) and have someone change a portion of that variable at the time of deployment.

Upvotes: 2

Related Questions