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. Access web.config file from a web service

Access web.config file from a web service

Scheduled Pinned Locked Moved ASP.NET
question
9 Posts 2 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.
  • B Offline
    B Offline
    BLOEDHOND
    wrote on last edited by
    #1

    How do I access a web.config from my web service I need to grab the connection string of one of many data basis Regards:confused:

    N 1 Reply Last reply
    0
    • B BLOEDHOND

      How do I access a web.config from my web service I need to grab the connection string of one of many data basis Regards:confused:

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Access it the same way you normally would, ConfigurationManager.ConnectionStrings


      only two letters away from being an asset

      B 1 Reply Last reply
      0
      • N Not Active

        Access it the same way you normally would, ConfigurationManager.ConnectionStrings


        only two letters away from being an asset

        B Offline
        B Offline
        BLOEDHOND
        wrote on last edited by
        #3

        Sorry I'm lost here Bit more info please Regards

        B N 2 Replies Last reply
        0
        • B BLOEDHOND

          Sorry I'm lost here Bit more info please Regards

          B Offline
          B Offline
          BLOEDHOND
          wrote on last edited by
          #4

          This What I have done It works fine But I need to get only the one from the default web.config file. Dim the_string_final As String = "" Dim the_string_temp As String = "" Dim counter As String = 0 Dim connectionStrings As ConnectionStringSettingsCollection = _ WebConfigurationManager.ConnectionStrings Try Dim connectionStringsEnum As IEnumerator = _ connectionStrings.GetEnumerator() Dim i As Integer = 0 While connectionStringsEnum.MoveNext() Dim name As String = connectionStrings(i).Name Debug.WriteLine(name) Debug.WriteLine(connectionStrings.Item(i).ConnectionString) counter = counter + 1 the_string_temp = "****Number: " + counter + " '" + connectionStrings.Item(i).ConnectionString + "'" + "NAME: " + name the_string_final = the_string_temp + the_string_final i += 1 End While Return the_string_final Catch ex As Exception End Try Return the_string_final The output: ****Number: 2 'Data Source=(local);User ID=sa1'NAME: SL2010WSConnectionString****Number: 1 'data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true'NAME: LocalSqlServer

          B 1 Reply Last reply
          0
          • B BLOEDHOND

            This What I have done It works fine But I need to get only the one from the default web.config file. Dim the_string_final As String = "" Dim the_string_temp As String = "" Dim counter As String = 0 Dim connectionStrings As ConnectionStringSettingsCollection = _ WebConfigurationManager.ConnectionStrings Try Dim connectionStringsEnum As IEnumerator = _ connectionStrings.GetEnumerator() Dim i As Integer = 0 While connectionStringsEnum.MoveNext() Dim name As String = connectionStrings(i).Name Debug.WriteLine(name) Debug.WriteLine(connectionStrings.Item(i).ConnectionString) counter = counter + 1 the_string_temp = "****Number: " + counter + " '" + connectionStrings.Item(i).ConnectionString + "'" + "NAME: " + name the_string_final = the_string_temp + the_string_final i += 1 End While Return the_string_final Catch ex As Exception End Try Return the_string_final The output: ****Number: 2 'Data Source=(local);User ID=sa1'NAME: SL2010WSConnectionString****Number: 1 'data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true'NAME: LocalSqlServer

            B Offline
            B Offline
            BLOEDHOND
            wrote on last edited by
            #5

            I Have tried this as well and no luck Dim rootWebConfig As System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Nothing) Dim connString As System.Configuration.ConnectionStringSettings If (0 < rootWebConfig.ConnectionStrings.ConnectionStrings.Count) Then connString = rootWebConfig.ConnectionStrings.ConnectionStrings("MyString") If Not (Nothing = connString.ConnectionString) Then Console.WriteLine("Mystring = {0}", connString.ConnectionString) Else Console.WriteLine("Mystring") End If End If

            1 Reply Last reply
            0
            • B BLOEDHOND

              Sorry I'm lost here Bit more info please Regards

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              WebConfigurationManager.ConnectionStrings["Default"].ToString()


              only two letters away from being an asset

              B 1 Reply Last reply
              0
              • N Not Active

                WebConfigurationManager.ConnectionStrings["Default"].ToString()


                only two letters away from being an asset

                B Offline
                B Offline
                BLOEDHOND
                wrote on last edited by
                #7

                Hi Mark Will try. :-D

                B 1 Reply Last reply
                0
                • B BLOEDHOND

                  Hi Mark Will try. :-D

                  B Offline
                  B Offline
                  BLOEDHOND
                  wrote on last edited by
                  #8

                  Hi Mark This works Dim the_string_final As String = WebConfigurationManager.ConnectionStrings("SL2010WSConnectionString").ToString() Thanx Ok now next question, How do I edit this field in the web.config file?

                  B 1 Reply Last reply
                  0
                  • B BLOEDHOND

                    Hi Mark This works Dim the_string_final As String = WebConfigurationManager.ConnectionStrings("SL2010WSConnectionString").ToString() Thanx Ok now next question, How do I edit this field in the web.config file?

                    B Offline
                    B Offline
                    BLOEDHOND
                    wrote on last edited by
                    #9

                    HI I tried this Dim Config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/SL2010WS") Dim csSettings As New ConnectionStringSettings("SL2010WSConnectionString", new_string) Dim csSection As ConnectionStringsSection = Config.ConnectionStrings csSection.ConnectionStrings.Clear() Config.Save(ConfigurationSaveMode.Modified) Return (new_string + " was saved to web.config") As soon as I try to save the file then the VS tells me I do not have access to this file. I checked but the file is not read only :confused:

                    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