Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Dynamic set ConnectionString of Connection Manager programmatically

$
0
0

Hi all,


I want to set programmatically the ConnectionString property of an ConnectionManager object with the value of an user-definied variable . In this variable I've set the ConnectionString for my database (like Data Source=bla;User ID=blub;...).

Therefore I want to use following code:

Package current = _app.LoadFromSqlServer(_rootFolder + "\\" + folder + "\\" + packagename, _server, _username, _pw, null);
            current.Variables.Add("SourceConnString", false, "User", "Data Source=localhost;User ID=bla; Initial Catalog=Blub;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;");
Variable v = current.Variables[connStringVar];


foreach (ConnectionManager c in current.Connections)
{ 
   c.DelayValidation = true; 
   c.ConnectionString = "@[User::SourceConnString]";
}

But I get following error message:

"The connection string format is not valid. It must consist of one or more components of the form X=Y, separated by semicolons. This error occurs when a connection string with zero components is set on database connection manager.\r\n".

Why can I set the ConnectionString from one variable? When i go into Property Expressions Editor in VS I can set only one user variable for ConnectionString.

I hope, somebody can help me. Thanks.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>