Search code examples
c#linuxasp.net-coresystemd

parsing ASP.NET Core connectionstring with Environtment= in systemd file


I've been following this guide To setup my ASP.NET Core app on an Ubuntu 18.04 server. I'm having some trouble though. While It works when i set the appsettings.json connectionstring, it doesn't seem to be able to read one entered as it if put in the .service file like so Environment=ConnectionStrings:SqlServer="connectionString"

Is there a clever way to handle this? something I've missed maybe? I have used systemd-escape "ConnectionStrings:SqlServer=\"<connectionString>\" to make sure it's properly escaped, but it just seems the app never receives the connstr.

Supposedly I will have more than one service of these running at the same time, and they will NOT be using the same database.


Solution

  • Figured it out.

    To parse a sqlserver connectionstring, it must be added like so:

    Environment:SQLCONNSTR_<stringname>=<connstring>
    

    There are three other types as well, excluding the custom one. THey can be viewed here

    Thanks to everyone who took the time to read this!