Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Setting a SQL Server based environment variable

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
  • 3
1 Solution
ValentinoVBI ConsultantCommented:
You should restart your BIDS after you've created your variable, otherwise it won't be known.
ValentinoVBI ConsultantCommented:
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.
PeterFrbAuthor Commented:
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
ValentinoVBI ConsultantCommented:
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/

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now