Using Web.Config to store DB ConnectionString

Topics: Administration, Customizing Orchard, Installing Orchard, Troubleshooting
Mar 27, 2011 at 3:01 PM

Hi,

I'm trying to get Orchard running on AppHarbor and would like to be able to store the database connection string in the Web.Config rather than App_Data/settings.txt. AppHarbor makes it easy to reconfigure the Web.Config file for their environment, which would make deploying to their environment a breeze.

Also - is there any documentation on the settings.txt file, or do I need to read the source?

I suppose I *could* re-write the settings.txt file on Application Startup to use the value from the web.config but it seems rather hacky.

 

Thanks

Phil

Mar 27, 2011 at 4:24 PM

If you open settings.txt up in Notepad you will see that it is less that 15 lines long.

The two lines you will want to focus on are:

DataProvider:
&
DataConnectionString:

Mar 27, 2011 at 5:38 PM

As long as I've been using ASP.NET (which has been some number of years now) I've never liked the pattern of storing connections strings (nor most application settings) in Web.config.

Since configuration-specific config transforms were introduced, this situation has been vastly improved upon, but it's still not ideal. Of course places like AppHarbor might provide workarounds, but they're still just that - workarounds (as I feel are the transforms).

What could help you in Orchard is the MultiTenancy module. Each site you set up will create a new folder in App_Data/Sites, each with its own settings.txt. So you can have a separate "live" config specifying your actual domain name for the host. This means you can manage settings for multiple sites without having to rely on any external system such as the one provided by AppHarbor. I haven't really done much experimentation with the MultiTenancy feature and there are potential problems (for instance, just importing your dev database won't work since content and settings seem to be tied to the tenant name).

I do think it would be nice if Orchard supported reading a connection string from Web.config to support both scenarios; however this wouldn't translate very well to the multi-tenant setup.

Mar 27, 2011 at 8:32 PM

Randompete: thanks, multitenancy looks like it will solve my problems.

Phil

On 27 Mar 2011 17:38, "randompete" <notifications@codeplex.com> wrote:

From: randompete

As long as I've been using ASP.NET (which has been some number of years now) I've never liked the pattern of storing connections strings (nor most application settings) in Web.config.

Since configuration-specific config transforms were introduced, this situation has been vastly improved upon, but it's still not ideal. Of course places like AppHarbor might provide workarounds, but they're still just that - workarounds (as I feel are the transforms).

What could help you in Orchard is the MultiTenancy module. Each site you set up will create a new folder in App_Data/Sites, each with its own settings.txt. So you can have a separate "live" config specifying your actual domain name for the host. This means you can manage settings for multiple sites without having to rely on any external system such as the one provided by AppHarbor. I haven't really done much experimentation with the MultiTenancy feature and there are potential problems (for instance, just importing your dev database won't work since content and settings seem to be tied to the tenant name).

I do think it would be nice if Orchard supported reading a connection string from Web.config to support both scenarios; however this wouldn't translate very well to the multi-tenant setup.



Read the full discussion online.

To add a post to this discussion, reply to this email (orchard@d...