Override connection string (from settings.txt)

Topics: Customizing Orchard
Feb 12, 2012 at 9:46 AM

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 the CMS.

Feb 12, 2012 at 11:39 PM

The connection string may change without notice? Really? Well, that pretty much does it for AppHarbor as a decent hosting platform for Orchard then. Too bad, I quite liked them.

Feb 13, 2012 at 2:33 PM

So, any ideas of how can this be done? Do I have to mess with the source code or is it possible otherwise?

On another note (off topic): What is your experience with AppHarbor and Orchard? I upload a site this weekend and the performance is really bad (locally runs just fine, it's a very simple site). You sound like you have used AppHarbor with Orchard before. Any tips?

Feb 13, 2012 at 2:59 PM

How are they able to create such a variable and inject it into their clients' applications? Is it just a plain old C# variable, or is SQLSERVER_CONNECTION_STRING a keyname for some collection data structure? 

Feb 13, 2012 at 4:29 PM

They change the web.config you upload and set this variable (and others) in <appSettings>

Feb 13, 2012 at 9:45 PM

I haven't tried it myself. Our documentation site (http://docs.orchardproject.net) runs on AppHarbor, but it's a plain ASP.NET Web Pages app, not an Orchard app.