connectionstring
-
There are several connectionstrings in the web.cofig file. <add name="DBConnection1" connectionString="Data Source=server1;Initial Catalog=database1;User Id=username;Password=password" providerName="System.Data.SqlClient"/> <add name="DBConnection2" connectionString="Data Source=server1;Initial Catalog=database2;User Id=username;Password=password" providerName="System.Data.SqlClient"/> ... ... I can retrieve each one of them by using the following code . i.e. string strConn = ConfigurationManager.ConnectionStrings["DBConnection1"].ConnectionString; Question: How can I retrieve all the connectionstrings into one array of strings so that I can populate the names of the databases into a dropdown control? I ask because the list of the connectionstring in the web.config can grow. So I need a way to retrieve all the connectionstrings without hardcoding the connectionname as I have done above. Any thoughts please? Thanks
-
There are several connectionstrings in the web.cofig file. <add name="DBConnection1" connectionString="Data Source=server1;Initial Catalog=database1;User Id=username;Password=password" providerName="System.Data.SqlClient"/> <add name="DBConnection2" connectionString="Data Source=server1;Initial Catalog=database2;User Id=username;Password=password" providerName="System.Data.SqlClient"/> ... ... I can retrieve each one of them by using the following code . i.e. string strConn = ConfigurationManager.ConnectionStrings["DBConnection1"].ConnectionString; Question: How can I retrieve all the connectionstrings into one array of strings so that I can populate the names of the databases into a dropdown control? I ask because the list of the connectionstring in the web.config can grow. So I need a way to retrieve all the connectionstrings without hardcoding the connectionname as I have done above. Any thoughts please? Thanks
My first thought is load the web.config into and xmldocument and parse it yourself using SelectNodes.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
My first thought is load the web.config into and xmldocument and parse it yourself using SelectNodes.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
There are several connectionstrings in the web.cofig file. <add name="DBConnection1" connectionString="Data Source=server1;Initial Catalog=database1;User Id=username;Password=password" providerName="System.Data.SqlClient"/> <add name="DBConnection2" connectionString="Data Source=server1;Initial Catalog=database2;User Id=username;Password=password" providerName="System.Data.SqlClient"/> ... ... I can retrieve each one of them by using the following code . i.e. string strConn = ConfigurationManager.ConnectionStrings["DBConnection1"].ConnectionString; Question: How can I retrieve all the connectionstrings into one array of strings so that I can populate the names of the databases into a dropdown control? I ask because the list of the connectionstring in the web.config can grow. So I need a way to retrieve all the connectionstrings without hardcoding the connectionname as I have done above. Any thoughts please? Thanks
<asp:DropDownList ID="ddl" runat="server"></asp:DropDownList>
ConnectionStringSettingsCollection a = ConfigurationManager.ConnectionStrings;
ListItem lst = new ListItem();
foreach (ConnectionStringSettings s in a)
{
lst = new ListItem(s.ConnectionString, s.ConnectionString);
ddl.Items.Add(lst);
}
ddl.Items.RemoveAt(0);you can use any loop once it is populated in ConnectionStringSettingsCollection. it populates one connection string from machine.config file. so i have removed 1st one. Hope this will be helpful for u. :laugh: