Unable to retreive connection strings from appsettings.json in asp.net core application

  • Thread starter Thread starter Congero
  • Start date Start date
C

Congero

Guest
in a simple example I have saved the following in an appsettings.json file for an asp.net core web api application

{
"ConnectionStrings": {
"BloggingDatabase": "Server=(localdb)\\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;"
}
}


In my startup.cs file I am testing to see if I can retrieve the code with the following :

var connectionString = Configuration.GetConnectionString("BloggingDatabase");

and it returns a null value

ultimately I would like to accomplish something like this

services.AddDbContext<BloggingContext>(options =>
options.UseSqlServer(GetConnectionString("BloggingDatabase"))

);

Continue reading...
 
Back
Top