Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

config.json - Adding database connection strings in ASP.NET vNext

I am in the process of learning ASP.NET vNext. I need to store two connection strings in the config.json file. How do I store those? Can I do this:

config.json

{
  "connectionStrings" : {
    "connection-1" : "server=...",
    "connection-2" : "server=..."
  }
}

I have not been able to find a schema for config.json. For that reason, I wasn't sure how to do it. I saw the use of IConfiguration here. Still, I wasn't sure how Configuration was available in the app.

like image 379
xam developer Avatar asked Jan 08 '15 20:01

xam developer


2 Answers

This is the official Configuration repo and this is a great blog post explaining the configuration system.

Long story short:

  1. You need one or more Microsoft.Framework.ConfigurationModel.* NuGet packages in your application. The list of available packages is here.
  2. Add the configuration sources that you need
  3. Build the config file(s)
  4. Read the configuration sources
like image 108
Victor Hurdugaci Avatar answered Oct 21 '22 17:10

Victor Hurdugaci


Here is how you can do it:

 {   
      "Data": {
        "connection-1": {
          "ConnectionString": "Server=..."
        },
        "connection-2": {
          "ConnectionString": "Server=..."
        }   
}

}
like image 2
BHR Avatar answered Oct 21 '22 19:10

BHR