Is there any way to change a connection string programatically? I mean user can pick which site he wants to use using a combobox, and load users on that particular site?
code for config as follows
<add key ="sampleconnectionstring" value="Server=sampleserver;Database=sampledb;User ID=sampleid;Password=samplepassword;Trusted_Connection=False;Encrypt=True;"/>
<add key ="sampleconnectionstring1" value="Server=sampleserver1;Database=sampledb1;User ID=sampleid1;Password=samplepassword;Trusted_Connection=False;Encrypt=True;"/>
<add key ="sampleconnectionstring2" value="Server=sampleserver2;Database=sampledb2;User ID=sampleid2;Password=;Trusted_Connection=False;Encrypt=True;"/>
<add key ="sampleconnectionstring3" value="Server=sampleserver3;Database=sampledb3;User ID=sampleid3;Password=samplepasswrd;Trusted_Connection=False;Encrypt=True;"/>
is there a programmatical(if that’s a word) way of changing between this connection strings depending on the selected item in the combo box? Any help would be appreciated. Thanks.
Depending on what you are using for the database you can load any connection string you want when loading.
For entity framework for example
For ADO.NET
For Linq To SQL
Use:
For a LinqDataSource, intercept the ContextCreating event and create the DataContext manually as above:
(Linq to SQL example taken from: Linq to Sql – Set connection string dynamically based on environment variable