Answered by:
Can Azure do some web.config transform logic?

Question
-
I have a Windows Azure website.
In my web.release.config file I have a connection string that points to a live database.
This project is open source and published on Github
I do not want my published web.release.config file to have the live database connection.
Is there a way to store a setting in Azure so it transforms this value into the web.config?
I see that I can store appsettings in Azure but I'm not sure what my connectionstring should look like in the web.config
<connectionStrings> <add name="RavenDB" connectionString="RavenDBKey" /> </connectionStrings> <appSettings> <add key="RavenDBKey" value="Url=http://localhost:8080;Database=DinnerPartyDB" /> </appSettings>
Thursday, June 21, 2012 2:33 PM
Answers
-
The Azure portal is going to add support to add arbitrary connection strings, which should resolve this. It's hard to be sure about the date, but hopefully it'll be in about a month.
Seth, are you also running into this relating to using RavenDB, or is your situation different?
- Marked as answer by Jim CheshireMicrosoft employee Thursday, July 5, 2012 1:26 PM
Saturday, June 30, 2012 7:16 PM
All replies
-
In your web.config, you can set the connection string to any value you want. Typically, it will be some local DB for development. e.g.
<connectionStrings> <add name="foo" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=foo;Integrated Security=SSPI" providerName="System.Data.SqlClient" /> </connectionStrings>
Then in the portal, in the configure tab, you add a connection string entry with a matching name (foo), and set the value to what it needs to be.
- Edited by David Ebbo Thursday, June 21, 2012 3:14 PM
Thursday, June 21, 2012 3:14 PM -
The configure option only allows to add appsettings not connection strings.
My connection string is not to a SQL Azure database too, its a URL over at RavenHQ.com
- Edited by j.channon Thursday, June 21, 2012 3:27 PM
Thursday, June 21, 2012 3:16 PM -
Ah right, forgot about that. There is indeed an issue with the portal right now that it doesn't allow adding connection strings manually. It only includes the ones that are linked to the site using the portal, but clearly that won't work with an external database.
Let me investigate some more and get back to you.
Thursday, June 21, 2012 3:30 PM -
Thanks, look forward to itThursday, June 21, 2012 3:33 PM
-
Can you give an example of what the connection string config section looks like in your case (when it's fully configured to run)? Does it include a providerName? Or does Raven ignore the provider?Thursday, June 21, 2012 3:53 PM
-
It looks like this:
<add name="RavenDB" connectionString="Url=https://1.ravenhq.com/databases/DinnerParty-DinnerPartyDB; ApiKey=765c840c-129f-4j26-b3h0-994dec2b2d22" />
Thursday, June 21, 2012 3:56 PM -
Here is a hacky temporary workaround that may work, assuming that RavenDB completely ignores the providerName.
Instead of using connection strings in the portal, add an AppSetting with name SQLCONNSTR_RavenDB, and set the value to your connection string.
This may or may not work, and is just a temporary hack to try to unblock this until we figure out the right way to do this.
- Marked as answer by Apurva Joshi (AJ) Friday, June 22, 2012 4:35 AM
- Unmarked as answer by j.channon Friday, June 22, 2012 8:19 AM
Thursday, June 21, 2012 4:03 PM -
Bingo!
That seems to work.
Thanks for the help.
Can you tweet/reply here when this issue is fixed?
Thursday, June 21, 2012 4:06 PM -
Great!
Yes, we can use this thread to follow up on changes related to this.
Thursday, June 21, 2012 5:36 PM -
Actually we have a problem. I've been amending the setting and its created a ConnectionString now but every time I change the setting the connection string is being appended which now breaks my site.
Below is a screenshot with commented out api keys
UPDATE: I created a new setting called RavenDB1, modified my source to use RavenDB1 and all was ok.- Edited by j.channon Thursday, June 21, 2012 7:43 PM
Thursday, June 21, 2012 7:02 PM -
That's bizarre. You could also delete the RavenDB setting and recreate it. I would hope that it would work as well.
Note that we never actually modify the physical web.config file. Instead, we modify the config system at runtime to surface the new values. So there is no risk of corrupting the web.config file on the server. You should be able to see this by looking at the files over FTP.
Thursday, June 21, 2012 7:58 PM -
Deleting it does not change the connection strings! They stay as they were. Adding the setting back in with the same name then appends the existing connection string.
I see the web.config is not touched.
Thursday, June 21, 2012 8:04 PM -
Ah yes, I am able to repro this now, there the code is clearly getting confused by the use of the SQLCONNSTR_ prefixed appsetting. Well, this was just a hacky workaround that I wasn't sure would work well.
We need to fix the original problem to let you directly add your connection string in the portal.
Friday, June 22, 2012 9:30 PM -
Any update on this, David?
Seth D. Webster
Saturday, June 30, 2012 3:55 PM -
The Azure portal is going to add support to add arbitrary connection strings, which should resolve this. It's hard to be sure about the date, but hopefully it'll be in about a month.
Seth, are you also running into this relating to using RavenDB, or is your situation different?
- Marked as answer by Jim CheshireMicrosoft employee Thursday, July 5, 2012 1:26 PM
Saturday, June 30, 2012 7:16 PM -
Seth, note that this is now available in the portal. See my post for details!
David
Tuesday, September 11, 2012 10:26 PM