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. modify a connection string in the web.config file [modified]

modify a connection string in the web.config file [modified]

Scheduled Pinned Locked Moved ASP.NET
visual-studiohelpquestionworkspace
3 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.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    Hello VS 2005 I have my connection string in the web.config as followings appSettings connectionStrings add name="serviceMasterConnectionString" connectionString="Data Source=CF_DEVELOP\realitysql;Initial Catalog=ServiceMaster;User ID=;Password=" connectionStrings I can read the connection string using the following. but how do i change the connection string. imports system.web.configuration imports system.configuration Dim cnnString As String cnnString = WebConfigurationManager.ConnectionStrings("serviceMasterConnectionString").ConnectionString() cnn.ConnectionString = cnnString I tried the following and got an error message. config.ConnectionStrings.ConnectionStrings("serviceMasterConnectionString").ConnectionString = "new connection string" config.Save() Error: Access to the path 'C:\Inetpub\wwwroot\CodeRedIncidents\web.config' is denied. I would like to change the connection string at run-time and save it. Does anyone have any code examples. Many thanks, Steve -- modified at 5:56 Thursday 12th April, 2007

    M 1 Reply Last reply
    0
    • S steve_rm

      Hello VS 2005 I have my connection string in the web.config as followings appSettings connectionStrings add name="serviceMasterConnectionString" connectionString="Data Source=CF_DEVELOP\realitysql;Initial Catalog=ServiceMaster;User ID=;Password=" connectionStrings I can read the connection string using the following. but how do i change the connection string. imports system.web.configuration imports system.configuration Dim cnnString As String cnnString = WebConfigurationManager.ConnectionStrings("serviceMasterConnectionString").ConnectionString() cnn.ConnectionString = cnnString I tried the following and got an error message. config.ConnectionStrings.ConnectionStrings("serviceMasterConnectionString").ConnectionString = "new connection string" config.Save() Error: Access to the path 'C:\Inetpub\wwwroot\CodeRedIncidents\web.config' is denied. I would like to change the connection string at run-time and save it. Does anyone have any code examples. Many thanks, Steve -- modified at 5:56 Thursday 12th April, 2007

      M Offline
      M Offline
      Mayank Parmar
      wrote on last edited by
      #2

      I don't know wheather you can edit Web.config or not. But I have done this thing using xml file. I have add key connectstring in xml file. And I can chamge it runtime. Hope you like using xml file:|

      Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India

      S 1 Reply Last reply
      0
      • M Mayank Parmar

        I don't know wheather you can edit Web.config or not. But I have done this thing using xml file. I have add key connectstring in xml file. And I can chamge it runtime. Hope you like using xml file:|

        Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India

        S Offline
        S Offline
        steve_rm
        wrote on last edited by
        #3

        Hello, I am sure you can modify the web.config file. After all its only xml. Moreover, how would you change the connection string if you wanted to connect to another database at run-time. I am sure I am not to far off, any extra help would be most grateful, Steve

        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