Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeesh MenothRank #118 · 18.4K reputationPosted Nov 15, 2022, 7:23 AM EST
Hi Naresh,
You can explain a bit more about your question? As a simple answer Connection string is an exact replacement of Web config ( Old ASP.NET Projects ).
Reference :
https://stackoverflow.com/questions/68980778/config-connection-string-in-net-core-6
Vishal YelveRank #178 · 13.6K reputationPosted Nov 15, 2022, 1:14 AM EST
In ASP.NET Core the configuration system is very flexible, and the connection string could be stored in
appsettings.json, an environment variable, the user secret store, or another configuration source.In appsettings.json
{ "ConnectionStrings": { "BloggingDatabase": "Server=(localdb)\\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;" }, }Then the context is typically configured in
Startup.cswith the connection string being read from configuration. Note theGetConnectionString()method looks for a configuration value whose key isConnectionStrings:. You need to import the Microsoft.Extensions.Configuration namespace to use this extension method.public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BloggingDatabase"))); }for more details please refer below link
https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Nov 15, 2022, 3:01 AM EST
https://www.c-sharpcorner.com/Blogs/database-connections-in-asp-net-core-20
Rajesh GamiRank #30 · 41.5K reputationPosted Nov 15, 2022, 7:55 AM EST
ASP.NET Core
In ASP.NET Core the configuration system is very flexible, and the connection string could be stored in
appsettings.json, an environment variable, the user secret store, or another configuration source. See the Configuration section of the ASP.NET Core documentation for more details.For instance, you can use the Secret Manager tool to store your database password and then, in scaffolding, use a connection string that simply consists of
Name=.dotnet user-secrets set ConnectionStrings:YourDatabaseAlias "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=YourDatabase" dotnet ef dbcontext scaffold Name=ConnectionStrings:YourDatabaseAlias Microsoft.EntityFrameworkCore.SqlServerOr the following example shows the connection string stored in
appsettings.json.{ "ConnectionStrings": { "BloggingDatabase": "Server=(localdb)\\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;" }, }Then the context is typically configured in
Startup.cswith the connection string being read from configuration. Note theGetConnectionString()method looks for a configuration value whose key isConnectionStrings:. You need to import the Microsoft.Extensions.Configuration namespace to use this extension method.public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BloggingDatabase"))); }