<p>I'm looking for a way to configure a DB connection at runtime; specifically using the Enterprise Library.  I see that there's a *.Data.Configuration (or something close to this ... don't recall off the top of my head) assembly but am finding not much on the interwebs.  Complicating matters is the fact that the API help is broken on Vista.</p>

<p>Now, I found this work-around:</p>

<pre><code>Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringSettings connection = new ConnectionStringSettings();
connection.Name = "Runtime Connection";
connection.ProviderName = "System.Data.OleDb";
connection.ConnectionString = "myconstring";
cfg.ConnectionStrings.ConnectionStrings.Add(connection);
cfg.Save(ConfigurationSaveMode.Modified);

ConfigurationManager.RefreshSection("connectionStrings");
var runtimeCon = DatabaseFactory.CreateDatabase("Runtime Connection");
</code></pre>

<p>And although it gives me what I want, it permanently edits the App.config. Sure I can go back and delete the changes, but I'd rather not go through this hassle.</p>

[{'answer_id': 15704, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re using a winforms app you could try using <a href="http://msdn.microsoft.com/en-us/library/aa221771(office.11).aspx" rel="nofollow noreferrer">UserProperties</a> to store this info. Another possible solution could be <a href="http://msdn.microsoft.com/en-us/library/2tw134k3.aspx" rel="nofollow noreferrer">custom configuration sections</a>.</p>\n'}, {'answer_id': 15714, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 0, 'selected': False, 'text': "<p>If you don't want it saved, you do not need to execute the cfg.Save command. </p>\n\n<p>The Configuration object will store your changes until it isn't needed anymore.</p>\n"}, {'answer_id': 16372, 'author': 'xanadont', 'author_id': 1886, 'author_profile': 'https://Stackoverflow.com/users/1886', 'pm_score': 0, 'selected': False, 'text': '<p>Nope, you must save in order for the EntLib (and, I suspect, any other tool) to see the changes.</p>\n'}]
['https://Stackoverflow.com/questions/15700', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1886/']