Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1285 posts 3917 karma points c-trib
    Mar 08, 2023 @ 16:11
    Dan
    0

    Configuring database connections for local/production

    Hi,

    I'm new to .NET Core and the 'deployment' side of Umbraco 10. I'd like to deploy an Umbraco 10 site to a client VM. I've created a publish profile (FTP version as that's all the host server supports) and deployed the files up without any issues. However, I need to update the db connection string. I gather this should be done by using an environment-specific appsettings.json file for production, but I'm struggling to find any explanations/documentation on exactly how to do this without a good previous understanding of environment variables etc.

    At the moment I have a relatively 'vanilla' Umbraco instance, so it comes with a properties/launchSettings.json file, populated with the following:

    {
      "$schema": "https://json.schemastore.org/launchsettings.json",
      "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
          "applicationUrl": "http://localhost:46505",
          "sslPort": 44358
        }
      },
      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        },
        "Umbraco.Web.UI": {
          "commandName": "Project",
          "dotnetRunMessages": true,
          "launchBrowser": true,
          "applicationUrl": "https://localhost:44358;http://localhost:46505",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }      
        }
      }
    }
    

    Do I need to add a 'production' or 'release'(?) setting in there? If so, is there an example as it's not obvious to me which parts to replicate and what things should be called?

    Then how about appsettings.{environment}.json? Should I create a production or release version of that? (Which?) If so, does anyone have an example of what it should contain in order to override the local connection setting with a production one?

    If anyone could shed any light on this it would be much appreciated. I'm sure it's easy when you know how! 😅

  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 08, 2023 @ 16:23
    Huw Reddick
    0

    There is a post in the Umbraco Discord channel about this exact thing :)

    https://discord.com/channels/869656431308189746/882984410432012360/1082655949287850017

    May be worth joining and taking a look.

  • Dan 1285 posts 3917 karma points c-trib
    Mar 08, 2023 @ 16:50
    Dan
    0

    Thanks Huw. The stuff about Papercut/SMTP? I see from that I can create a machine config for my local machine but then that's confusing in itself as I thought that's what the 'Development' config was for. It mentions adding code to Program.cs to register the machine config but no mention of adding anything into properties/launchSettings.json, which I thought was how the publish profile knew which config to use?

  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 08, 2023 @ 17:09
    Huw Reddick
    0

    I've never touched launch settings myself tbh, I normally just rely on appsettings.json for my live site and appsettings.develoment locally, I just like the idea of using the machine name method as it is then pretty obvious which is getting used.

  • Dan 1285 posts 3917 karma points c-trib
    Mar 08, 2023 @ 17:24
    Dan
    0

    So you have two database connection settings — one in appsettings.json and another in appsettings.development.json? And it just defaults such that the dev one is used locally but when it's deployed the publish task discards that and uses appsettings.json? So effectively you haven't taken any steps to create a production/release variation, you've just stuck with appsettings.json and appsettings.development.json and it 'just works'?

    That would work for me — I don't have any desire to make things any more complicated, but would like to not have to manually switch connection strings every time I deploy. Am I understanding the above correctly? Thanks - appreciate the clarification.

  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 08, 2023 @ 18:43
    Huw Reddick
    0

    Yes correct, I just don't push the appsettings.development to the server

Please Sign in or register to post replies

Write your reply to:

Draft