Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everybody,

My Requirement is in such a way that.
I have a no of connectionstring in web.config which are country wise set.
so when user has logged in depending on his country that no of connection string only to be loaded and not all.

And i suppose this should be only once at the start.

Please suggest me some thing

Thanks and regards
Posted

You can use following method:
<br />
System.Configuration.ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString <br />

You could execute select command using a SqlCommand object with the ExecuteReader method,
see: http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx
Look into the other methods available: http://msdn.microsoft.com/en-us/library/182ax5k8.aspx
for example, a delete command with the
<br />
ExecuteNonQuery()<br />
 
Share this answer
 
Hey there,

It would be very easy, isn't it? You said you got a list of connection strings in the config file. So each connection string is given a name, right?
C#
foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)
{
  Console.WriteLine(connectionString.Name);
}

You can either pull these names from the config and put it in a drop down or you can write a mapping between the connection string names with some other text that you want to display and show that in the drop down. The latter method only makes sense when the connection string names doesn't make sense or something.

Hope this helps, Regards
 
Share this answer
 
Comments
suhailnoorpawane 5-Sep-12 3:15am    
Hey buddy thanks for response.
But the thing is that i have got country dropdown like INDIA,Germany,US and if i select INDIA INDIA specific connectionstring should only load and so on for others. your solution will get only name but wont load that specific connection.
If i am right let me know

Thanks once again
CodeHawkz 5-Sep-12 7:37am    
List<string> names = new List<string>();
foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)
{
names.Add(connectionString.Name);
}
// This for loop gives you the list of names, bind this to the drop down


string countryConnectionString = ConfigurationManager.ConnectionStrings["selected connection string name"].ToString();
// This gets you the connection string based on the selection

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900