- Home
- .NET coding challenges
- Add a connection string to appsettings.json
Add a connection string to appsettings.json
In appsettings.json, we can use the ConnectionStrings object to add a key/value property with a connection string.
This allows us to connect our ASP.NET Core web app to a SQL Server database.
We have this connection string that we wish to add to our ASP.NET Core app.
Server=localhost; Database=MyDatabase; Trusted_Connection=true; Trust Server Certificate=true; MultipleActiveResultSets=true; Integrated Security=true;
Our appsettings.json file looks like this:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
How would we add this connection string to the appsettings.json file with a MyDatabaseDbContext
key?
Give us your anonymous feedback regarding this page, or any other areas of the website.
Related challenges

How to read an appsettings.json value in ASP.NET Core
See if you can read an appsettings.json configuration value from IConfiguration in an ASP.NET Core with our .NET coding challenge.