Override connection string (from settings.txt) in Orchard CMS
Asked Answered
P

3

5

I deployed a web site in AppHarbor which uses a MS SQL database. AppHarbor provides me with a connection string which I entered in settings.txt and it seems to work fine BUT AppHarbor suggests to use the SQLSERVER_CONNECTION_STRING variable instead.

That is because the connection string may change without notice so the only safe way is to use the variable mentioned.

Accessing the configuration variables below should be done programatically, as the values may be updated by the add-on provider without notice.

Is there a way to override the DataConnectionString setting from settings.txt and set the application to use the SQLSERVER_CONNECTION_STRING variable instead? I assume AppHarbor somehow sets those variables as appSettings.

P.S. This is my first application with Orchard, I am not proficient with this CMS.

Perforate answered 11/2, 2012 at 21:20 Comment(0)
Y
6

The connection string is set in the ShellSettingsManager class. I'm not sure you can easily replace this dependency from a module, but you could certainly just change the line of code that sets the connections string...

shellSettings.DataConnectionString = value;  //use your config value instead

ShellSettingsManager is an implementation of IShellSettingsManager so you have some flexibility there if you want to just implement your own too.

Yerkovich answered 12/2, 2012 at 8:16 Comment(4)
To be honest, I was hoping for a solution that didn't include messing with the source code but I finally followed your suggestion shellSettings.DataConnectionString = ConfigurationManager.AppSettings["SQLSERVER_CONNECTION_STRING"] ?? value;Perforate
I know this is a bit dated and the Orchard framework source has changed, but in version 1.6 it looks like this could be accomplished without changing the core Orchard source. One might create a custom implementation of IShellSettingsManager. The IoC for ShellSettingsManager is registered using Autofac, so it should be possible to create a new ContainerBuilder, then call RegisterType or RegisterInstance, and finally call Update passing in the core Container originally returned by OrchardStarter.CreateHostContainter(). I'm working on a similar approach now, looking for a good injection point.Tetroxide
Got it! I'll post a follow-up with a link to the module once I have it up on the Orchard Gallery :DTetroxide
Published :) See my answer below or visit gallery.orchardproject.net/List/Modules/…Tetroxide
T
2

I've just published my "Configuration Shell Settings" module (Fineout.ConfigShellSettings) to the Orchard Gallery. This module finally provides a painless way to manage Orchard site (tenant) shell settings via configuration management.

Download the Configuration Shell Settings module from the Orchard Gallery!

I've copied the module package description (version 1.0.1) below:

Allows Orchard shell settings for tenants to be specified through configuration application settings, i.e. "Web.config" instead of "Settings.txt". This allows site (tenant) settings control via build configuration management, considerably simplifying the build and deploy process for most environments and infrastructures.

Upon enabling the feature, existing shell settings for all tenants will be copied from respective "Settings.txt" files into AppSettings defined in "Orchard.Web/Web.config". Likewise, whenever the feature is disabled, existing AppSettings defined for all tenants will be copied back to the respective "Settings.txt" files. This allows the feature to be managed without any need for any manual file manipulation or code changes.

As this is the initial version of the module, I expect there will be plenty of room for improvement and the occasional bug; I'd love any feedback or ideas anyone has. I hope this contribution will prove useful and time-saving for the community.

Tetroxide answered 19/10, 2013 at 17:41 Comment(0)
N
0

Deploying orchard to appharbor might not be worth the effort. Appharbor wipes out the entire app when doing a deploy so uploaded media gets wiped out too. You can get around this by hosting the media folder somewhere else, like amazon s3.

But you also don't have FTP access to log files or anything else. (at least not the last time I looked).

Plus u can't take advantage of web deploy.

You can make it work but orchards architecture creates much friction with appharbor's deployment model.

Don't get me wrong. I love appharbor. But orchard is square peg. I got my sight working on appharbor but 4 months later I found I was afraid to update because too many non default settings. Finally, threw in towel and paid $8 per month at arvixe. Much less friction now.

Nadabus answered 13/2, 2012 at 1:56 Comment(2)
I like using the free AppHarbor plan for demos (so the clients can check out their site while in development), and for that purpose (and not only that of course) AppHarbor is excellent. Possibly I'll move the site elsewhere when it's done, but development will take some time and I don't want to tell the customer to start paying while the project is in development. Thanks for your info though.Perforate
If you use the S3 storage provider, the files become less of a problem. We've written a guide here: support.appharbor.com/kb/tips-and-tricks/…Stigmasterol

© 2022 - 2024 — McMap. All rights reserved.