Connection Strings
Does anyone have a good method for handling production vs. dev connection strings? I've seen the article on the setting. I can check that when my app starts up and load my connection string from an alternate place, but then I'm going to have to change every line from DataContext db = new LinqToDBDC() to DataContext db = new LinqToDBDC(globalString) and that would be mildly annoying.
Discussions are closed to public comments.
If you need help with AppHarbor please
start a new discussion.
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac
Support Staff 1 Posted by rune on 27 Jan, 2011 12:23 AM
Hi,
when you add a database on AppHarbor you can set an alias for it. If you use this alias as the connection string name you'll be using in your configuration file, we'll replace it when the application is deployed. This should make shifting connection string between your local environment and the production environment transparent to your other code.
Let me know if I this doesn't answer your question.
Best regards,
Rune
rune closed this discussion on 27 Jan, 2011 12:23 AM.
skilesare re-opened this discussion on 27 Jan, 2011 03:03 AM
2 Posted by skilesare on 27 Jan, 2011 03:03 AM
Ok, How do I go about setting up that alias? I don't see a place to
do it in the UI.
...And I guess I'm a little unclear on how to this works in practice.
You set up an alias...say 'MWDB'. Then I use that as my
connectionstring name. Then when deploy happens you replace MWDB with
the db associated with my app?
Thanks for the help,
-Austin
3 Posted by siger on 27 Jan, 2011 06:24 AM
In your dashboard, under "Databases", click 'Show' to the right. On the top of that new page, click "Edit database", where you can set up an alias.
I'll also be experimenting with this, and the way I understand it is like this:
- Set your alias as "MWDB" - In your code:
Support Staff 4 Posted by rune on 27 Jan, 2011 06:33 AM
Hi,
Thanks a lot for helping out Marvyn! The 'edit database' option was added only an hour ago, so I can understand why Austin couldn't find it :-) This feature was poorly documented, so I've added some guidance when creating a new db.
I have also documented this in more detail in the Managing Environments article (http://support.appharbor.com/kb/getting-started/managing-environments). Let me know if this works out for you or I should make something more clear.
Thanks,
Rune
5 Posted by siger on 27 Jan, 2011 06:40 AM
Ha, I guess it was added right before I tried to find this option :)
Thanks for posting the kb article. Comments:
- In the Environment example, the example sets a value of "Test" but the explanation below says that the value will be "Debug" on your development machine. - It'd be nice to have an example for the connection string like for the Environment - Typo: "When you create a database on AppHarbor you can specify an name for it." -> "an name" should be "a name"
Support Staff 6 Posted by rune on 27 Jan, 2011 07:05 AM
Thanks for your inputs. I guess the explanation was a little unclear - we actually set the environment to "Test" (debug is the value set in yoursource control) while running the tests. After the tests has been run and the application is deployed, it will have the value "Release". We figured it was probably a good idea to have different environments for testing and release modes. I've updated the article to better reflect this.
Typo fixed and I've added an example :-)
7 Posted by skilesare on 27 Jan, 2011 10:37 AM
I feel a lot less silly knowing that this was just added. Thanks for
the info all. This is a great feature....but..(There is always a but
isn't there?) What if I need additional parameters in my
connectionstring. Specifically I need to set
MultipleActiveResultSets=True; or LinqToSql will howl under the
pressure of more than a couple of concurrent users. It would be great
if I could specify both an alias and the connection string I want it
replaced with. This would also be useful if I wanted to temporarily
point to an off site DB.
-Austin
Support Staff 8 Posted by rune on 28 Jan, 2011 09:20 AM
Hi Austin,
I would actually recommend that you use a factory for making your LinqToDBDC instances. This way you would only have to configure it once depending on the environment key. I can see why it would be a pain to put in a connection string in every instance, but hey, that's what factories are for ;-)
You can add the ability to specify a connection string as a feature request on our feedback page (http://appharbor.com/feedback). I guess most users can use the connection string provided from us as is, but I might be wrong on this one.
Best regards,
Rune
rune closed this discussion on 28 Jan, 2011 09:20 AM.