Read Entity Framework 6 Connection String from appsettings.json file in ASP.NET CORE

appsettings asp.net-core entity-framework-6

Question

I have a app.config xml file to save entity framework's connection strings as the following example:

<configuration>
    <connectionStrings>
        <add name="MyEntities" connectionString="metadata=res://*/EntityFramework.MyEntities.csdl|res://*/EntityFramework.MyEntities.ssdl|res://*/EntityFramework.MyEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myserver;initial catalog=Example;persist security info=True;user id=myId;password=myPassword;multipleactiveresultsets=false;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

But I'm using ASP.NET Core, I manage multiple servers with an enviroment variable. so I need to save this connection string in my appsettings.{enviroment}.json, read this connection and set to the property entity framework context.

1
4
1/25/2017 7:46:11 PM

Popular Answer

I think you are looking for something like the following construction.

  "ConnectionStrings": {
    "MyEntities": "metadata=res://*/EntityFramework.MyEntities.csdl|res://*/EntityFramework.MyEntities.ssdl|res://*/EntityFramework.MyEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myserver;initial catalog=Example;persist security info=True;user id=myId;password=myPassword;multipleactiveresultsets=false;application name=EntityFramework"
  }
0
1/23/2018 10:18:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow