In my windows forms application I have a scenario like this:
I have 5 checkboxes which awaits user input. When the user clicks a checkbox,my application should connect to a database. Clicking each checkbox should connect to different different databases. For simplicity I have given my ip addresses and all details in app config as
<add key="SQLServer1" value="mmm.mm.mm.m,abcd" />
<add key="SQLServer2" value="nnn.nn.nn.n,wxyz" />
I have written the code like this:
ConnectionString = "Data Source=" + ***** + ";Initial Catalog=" + Master + ";Persist Security Info=True;Connect Timeout=0;User ID=" + ConfigurationSettings.AppSettings["username"] + ";Password=" + ConfigurationSettings.AppSettings["password"];
I should get help from you people where I marked *. What I meant by * is that my application should be able to connect with relevant ip based on what the user clicked..
Is there any chance for what I said?
Any other alternatives are also really appreciated..
Tagproperty of the checkboxes. Write the key "SQLServer?" in thatTagproperty, in the Visual designer and in whateverCheckBoxevent handler you had in mind just do something like:ConnectionString = "Data Source=" + ConfigurationManager.AppSettings[ (sender as Control).Tag.ToString() ] + ";Initial Catalog=" + Master + .....