Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. connectionstring

connectionstring

Scheduled Pinned Locked Moved ASP.NET
questiondata-structuresdiscussion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arkiboys
    wrote on last edited by
    #1

    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

    T S 2 Replies Last reply
    0
    • A arkiboys

      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

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      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]

      A 1 Reply Last reply
      0
      • T The Man from U N C L E

        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]

        A Offline
        A Offline
        arkiboys
        wrote on last edited by
        #3

        Any other thoughts apart fro mxmldocument? Thanks

        1 Reply Last reply
        0
        • A arkiboys

          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

          S Offline
          S Offline
          Sanjay Jaiswal 1234567
          wrote on last edited by
          #4

          <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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups