Copied to clipboard

Flag this post as spam?

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


  • Donatello 5 posts 44 karma points
    Mar 18, 2015 @ 15:35
    Donatello
    0

    Use a different connection string

    Hi

    We're trying to have Umbraco use a connection string we pass it from the code. Reason being, we get the connection string from outside of the web.config and we can't change this constraint.

    Is it possible to do this? We are not allowed to modify the web.config from the source code as well so editing it from the code to add the UmbracoDbDSN parameter is not an option...

    Thanks

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 18, 2015 @ 16:44
    Alex Skrypnyk
    0

    Hi Donatello,

    Welcome to our community,

    Try to look at this code :

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

    Thanks, Alex

  • Donatello 5 posts 44 karma points
    Mar 18, 2015 @ 16:57
    Donatello
    0

    Hi Alex

    thanks a lot for your help.

    We've tried and used this successfuly but we are unfortunately not allowed to modified the web.config file anymore...so this solution couldn't work for us.

     

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 18, 2015 @ 17:07
  • Donatello 5 posts 44 karma points
    Mar 18, 2015 @ 19:30
    Donatello
    100

    Spent some time testing this solution as well but whichever way I try to access the configuration it is read only (ApplicationContext.DatabaseContext.Database.Connection.ConnectionString is readonly)

    What I was hoping for was a way to hook up in the Umbraco database layer initialization and being able to "inject" a different connection string. But looking at the Umbraco source code, it doesn't seem to be feasable...any suggestion would be appreciated.

  • NAGENDRA 2 posts 71 karma points
    Feb 11, 2020 @ 21:08
    NAGENDRA
    0

    Hi Donatello,

    just want check with you, did you find any way to resolve your issue. I'm also facing the same issue.

    Thanks, Nagendra

Please Sign in or register to post replies

Write your reply to:

Draft