There could be several ways you could achieve this. One easy way would be to create a code that could dynamically determine the connectionstring based on user selection from dropdown and using a predefined sets of ConnectionString you have in your config file.
Lets say you have defined following connectionstrings,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="Development" connectionString="data source=MyDataSource;Initial Catalog=DevDatabase;user id=sa;Pwd=devpassword;"/>
<add name="Test" connectionString="data source=MyDataSource;Initial Catalog=TestDatabase;user id=sa;Pwd=testpassword;"/>
</connectionStrings>
</configuration>
Now you can have following code to loop through the connectionstring and determine which one should be used based on the dropdown selection
string selectedEnvironemntName = "Development"; //set from dropdown selection
var predefinedConnections = ConfigurationManager.ConnectionStrings;
SqlConnectionStringBuilder connStringBuilder = null;
foreach( ConnectionStringSettings connString in predefinedConnections)
{
if (connString.Name == selectedEnvironemntName )
{
connStringBuilder = new SqlConnectionStringBuilder(connString.ConnectionString);
}
}
//the below two lines can be anywhere in your solution as long as you can pass the connStringBuilder to SqlConnection definition
SqlConnection connection = new SqlConnection();
connection.ConnectionString = connStringBuilder.ConnectionString;
Ofcourse, one dependency is there. You have to ensure that the dropdown values are loaded based on the ConnectionString name from the config file. Having this dependency ensures that adding a new ConnectionString in your config file will automatically result in having a new entry in your dropdown in UI