Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Oleg 2 posts 22 karma points
    Oct 30, 2013 @ 10:32
    Oleg
    0

    Set umbracoDbDSN programmatically

    Hello, I'm using Umbraco 4.9.1 and Umbraco 6.1.6. Question is: how can I set umbracoDbDSN parameter programmatically in Global.asax in Application_Start method or maybe somewhere else?

    Thanks for the help.

  • MK 429 posts 905 karma points
    Oct 31, 2013 @ 23:16
    MK
    0

    Are you trying to set the connection string dynamically?

     

     

  • Oleg 2 posts 22 karma points
    Nov 01, 2013 @ 08:39
    Oleg
    0

    Yes. I'm using umbraco.GlobalSettings.DbDSN.

    But when site loads first time and umbracoDbDSN in the web.config and a connection string which is set dynamically are not the same I get exception. Because actually Umbraco uses the old connection string. Second site loading is successful.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Nov 02, 2013 @ 20:34
    Andy Butland
    0

    I don't know the answer to this but would suggest it's probably worth looking at the source code.  The installer wizard must be doing this so I would expect you could see what's going on there and utilise it for your own requirements.  In case you are unaware the code is available here.

  • Dan Lister 416 posts 1974 karma points c-trib
    Nov 04, 2013 @ 10:12
    Dan Lister
    0

    Have a look at this Stack Overflow question. It seems to have the answer you are looking for:

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    config.AppSettings.Settings["umbracoDbDSN"].Value = “New Connection String”;
    config.Save(ConfigurationSaveMode.Modified, true);
    ConfigurationManager.RefreshSection("appSettings");

     

     

Please Sign in or register to post replies

Write your reply to:

Draft