Copied to clipboard

Flag this post as spam?

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


  • Bo Mehlsen 1 post 21 karma points
    Sep 01, 2014 @ 20:28
    Bo Mehlsen
    0

    Connection string in code

    Hello everybody,

    Umbraco version 7.1.4 / 7.1.6

    Is it possible to retrieve the connection string (umbracoDbDSN) for the database from code rather than from the web.config? 

    I would like to do it without modifying the web.config file or hacking the core.

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 01, 2014 @ 23:12
    Dennis Aaen
    0

    Hi Bo and welcome to Our.

    I must say that I am not a .NET developer but working as front end developer, but I would try to help you as much as I can.

    I have found these articles about how change a database connection string from code, maybe this can help you to get your wish come true to retrieve the connection string for the database from code rather than from the web.config.

    http://codebetter.com/petervanooijen/2006/08/11/change-a-database-connection-string-from-code/

    http://our.umbraco.org/forum/developers/api-questions/45845-Set-umbracoDbDSN-programmatically

    http://stackoverflow.com/questions/13328895/moving-the-connection-string-location-from-app-settings-in-umbraco

    Hope this can help you.

    /Dennis

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Sep 02, 2014 @ 17:20
    David Brendel
    0

    Haven't tryied it but from intellisense research in visual studio it seems that you can get the connection string with this: ApplicationContext.DatabaseContext.Database.Connection.ConnectionString.

    Hope that helps!

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jan 02, 2018 @ 17:53
    Andy Butland
    2

    Replying from the future as found the above isn't available in an application start-up handler.

    ApplicationContext.Current.DatabaseContext.ConnectionString is though.

    Andy

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies