locked
Changing connectionstring area of app.config in vb.net RRS feed

  • Question

  • Hi,
    I need to change the connectionstring area of my aap.config file in vb.net.  I have tried several codes but nothing worked for me.  I was suggested following code
         Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
            Dim connectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
            connectionStringsSection.ConnectionStrings("Blah").ConnectionString = "Data Source=blah;Initial Catalog=blah;UID=blah;password=blah"
            config.Save()
            ConfigurationManager.RefreshSection("connectionStrings")
    But I do not understand what will be "Blah" in my code?  Also how does this change the text?
    Secondly, if I use Readalltext and replacetext and then writealltext, will it be ok or it can cause any problems?
    Thanks
    Monday, February 6, 2012 7:37 AM

Answers

  • Hello,

    Try the below links. They will resolve the issue

    http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx

     

    http://forums.asp.net/p/1107224/1696691.aspx

     

    http://www.codeproject.com/KB/dotnet/Change_AppConfig_File.aspx

     

    http://blogs.syrinx.com/blogs/dotnet/archive/2008/03/21/modify-app-config-on-the-fly.aspx

     

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1870864&SiteID=1

    • Proposed as answer by Mike Feng Wednesday, February 8, 2012 10:31 AM
    • Marked as answer by Mike Feng Tuesday, February 21, 2012 9:12 AM
    Monday, February 6, 2012 9:54 AM