title: Umbraco, Azure deployment slots and Connection Strings
body: <p>We're trying to leverage Azures deployment slots for an Umbraco site we've built. </p>
  
  <p>By default Umbraco uses a DSN defined in the <em>connectionStrings</em> sections of the web.config and we want it to use the connection string for the deployment slot it's sitting in.</p>
  
  <p><strong>What we've tried</strong></p>
  
  <p>Azure deployment slots put all defined app settings (and connection strings) into environment variables and to access them we can use <code>Environment.GetEnvironmentVariable()</code> which works but there doesn't seem to be a way to tell Umbraco to do this.</p>
  
  <p>So in OnApplicationInitialized() (in /App_Code/Core/UmbracoAppStart.cs) we loaded the connectionstring section from the web.config, grabbed the connstr from env vars, added the DSN to the connectionstring section and saved.
  The correct connection string is grabbed and stored but this seems to recycle the app (due to a web.config change) and thus we just get timeouts. (Or Umbraco XML cache errors, or it takes 20 mins to load the page).</p>
  
  <p>I know you can store the appsettings and connectionstrings sections in separate files. But the <em>file</em> attribute (that doesn't cause a recycle if the referenced file is changed) doesn't work on the connectionStrings section - only the <em>configSource</em> attribute and that DOES recycle if changed.</p>
  
  <p>(from: <a href="https://stackoverflow.com/questions/6940004/asp-net-web-config-configsource-vs-file-attributes">ASP.NET web.config: configSource vs. file attributes</a>)</p>
  
  <p><strong>Help</strong></p>
  
  <p>Has anyone found a way around this?
  <em>We simply need to get Umbraco to use the deployment slot connection string - not the one in webconfig</em>.</p>
  
  <p>I'm even willing to copy and paste blindly at the moment without understanding how it works - and I hate doing that :). But that's what happens when people agree when the client wants to go live just before Christmas...</p>