I have my connection string specified in appsettings.json and appsettings.Production.json, as follows:
{
"ConnectionStrings": {
"Database": "Host=localhost;Port=5432;Database=<mydb>;Username=<myuser>;Password=<mypw>"
}
(I've obviously removed the secrets from the string)
I then publish the solution. I can run it on the same system with dotnet <PathToThePublishedDLL>
just fine. But when I copy the published files over to the Linux server and run it with that dotnet command, I get the error:
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
at Npgsql.EntityFrameworkCore.PostgreSQL.Utilities.Check.NotEmpty(String value,
String parameterName)
at Microsoft.EntityFrameworkCore.NpgsqlDbContextOptionsExtensions.UseNpgsql(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 npgsqlOptionsAction)
at MapToGlobe.Startup.<ConfigureServices>b__2_0(DbContextOptionsBuilder options) in [path to the solution folder on my dev pc]\Startup.cs:line 25
In the Startup.cs file I have:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddEntityFrameworkNpgsql();
services.AddDbContext<DatabaseContext>(options => options.UseNpgsql(Configuration.GetConnectionString("Database"))).BuildServiceProvider();
}
Line 25 is the "services.AddDbContext" line.
I've found a number of questions and answers about this, but nothing I have tried has worked and at this point I'm not sure what to do.