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.
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.
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.
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
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!
Replying from the future as found the above isn't available in an application start-up handler.
ApplicationContext.Current.DatabaseContext.ConnectionString
is though.Andy
is working on a reply...