Solved

Setting a SQL Server based environment variable

Posted on 2012-03-12
4
187 Views
Last Modified: 2012-06-07
I am attempting to set an environment variable to point to a SQL Server connection in SSIS.  I have been looking online for an example of this, but to no avail.  After successfully setting an environment variable to an XML file, I thought it would be straightforward to set one to a SQL Server connection, but I think I’m doing something wrong.

I am experimenting with this and creating as simple an example as possible.  I have a table in AdventureWorks that contains the configurations I want (see below).  I have two Configuration Filters: SetVar_Hello and SetVar_Goodbye; and they each set the value of a variable test to “Hello” and “Good Bye”, respectively.

I created two environment variables (Control Panel / System / Advanced / Environment Variables / New), with these values:
SSIS_Config_Goodbye =
"CUSTOMIZE.AdventureWorks";"[dbo].[SSIS Configurations]","SetVar_Goodbye";

SSIS_Config_Hello =
"CUSTOMIZE.AdventureWorks";"[dbo].[SSIS Configurations]","SetVar_Hello";

The values of these I took from the Configuration String when I set the filters directly.  I include an image of the setup for setting the environment variable.  My expectation is that when I change the environment variable, the value of the variable test will toggle between “Hello” and “Good Bye”.  What happens instead is that the variable value doesn’t change.  I’d like to hear from anyone who has successfully set this up; and, hopefully, let me know what I’ve done wrong.

And extra credit: when I set a SQL Server variables directly, I find it disconcerting that the old settings I had go away, and the whole thing starts over.  The behavior appears to me a bug, sacrificing previously set values when coming back to the same filter.  If there is a way to keep the old values from going away, that would be great!

Sincerely, ~Peter Ferber
Config-Table.bmp
SQL-Server-ByEnvironmentVar.bmp
0
Comment
Question by:PeterFrb
  • 3
4 Comments
 
LVL 37

Expert Comment

by:ValentinoV
ID: 37715519
You should restart your BIDS after you've created your variable, otherwise it won't be known.
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 37715599
BTW: to set a connection string through an environment variable, you can just select the ConnectionString property of the connection manager when setting up the configuration (Package Configuration Wizard > Select Target Property page).

The above assumes that your environment variable contains a valid connection string.  To make sure it's correct, copy it from the ConnectionString property as well.
0
 

Author Comment

by:PeterFrb
ID: 37715833
I've attached a screenshot of both a indirect and direct configuration.  Having made the direct configuration, I reproduced the Configuration String value (as I can't copy the string, I had to retype it) and made that the value of my environment variable.  To adequately test, I closed and reopened the project, to no avail.  I've even experimented with warm and cold boots (Logging off and back in; restarting the computer), which still makes no difference.  I don't yet know why my environment variable is failing.

Thanks for the feedback, from which I always gain value.  I trust that I will eventually crack this case.  ~Peter

A direct and indirect configuration type
0
 
LVL 37

Accepted Solution

by:
ValentinoV earned 500 total points
ID: 37719656
Hmm, I think there's a misunderstanding of concepts here.  In particular, a "configuration string" is something totally different than a "connection string".

To get a view of a connection string, select the Connection Manager that points to the database containing your configuration table.  Then locate the ConnectionString property in the Properties pane.  The string that you see there is the value that you should give your environment variable.

What you seem to have done is used the Configuration String from the Package Configs, that's not how this works. (as you've noticed)

Here's a more visual explanation: http://www.jasonstrate.com/2011/01/31-days-of-ssis-environmental-variable1731/
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question