0

TLDR: ConnectionStrings for options.useSQLServer.GetConnectionString is returning null. Changing names does not work. Hardcoding the connection string did work, so it seems to be a config issue.

I've been running into an issue and have tried several solutions here on stack exchange but none have worked. Everything from changing the connection string name, to eliminating environment variables, and folders that have the name "Configuration". Wondering if at this point I have to explicitly state

I had to run the following code by hardcoding the connection string.

`builder.Services.AddDbContext<BethanysPieShopDbContext>(options => options.UseSqlServer("hardcodedConnectionString"));`

I have an appsettings.json

That is this:

`{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning",
      "Microsoft.EntityFrameworkCore.Database.Command": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DefaultConnection": "Server=MysettingsForServer"
  }
}` 

I've checked during the build and the add-migration command, and both are returning null. I'm new to .NET and I'm wondering if there is a setting the is overriding the appsettings.json file from being seen.

Is there something I have to do to force my application to read from a specific appsettings.json file?

thinker
  • 167
  • 3
  • 10

0 Answers0