you can use the connectionStrings tag in the app.config configuration. You can add as many as you want (giving them each separate key) and then extract them
example app.config xml (set the provider name to a valid provider, for example System.Data.SqlClient, and the corresponding connection string):
<?xml version='1.0' encoding='utf-8'?> <configuration> <connectionStrings> <clear /> <add name="firstDb" providerName="System.Data.ProviderName" connectionString="Valid Connection String;" /> <add name="secondDb" providerName="System.Data.ProviderName" connectionString="Valid Connection String;" /> </connectionStrings> </configuration>
an example of obtaining and listing them (in your case, you must create the corresponding elements in the drop-down list and set the values):
ConnectionStringSettingsCollection settings = ConfigurationManager.ConnectionStrings; if (settings != null) { foreach(ConnectionStringSettings cs in settings) { Console.WriteLine(cs.Name); Console.WriteLine(cs.ProviderName); Console.WriteLine(cs.ConnectionString); } }
Daniel Perez Nov 23 '10 at 14:16 2010-11-23 14:16
source share