Our ASP.NET 5 / MVC 6 project accesses our database through a business-level build, and then into a DAL (Database First) build. MVC 6 code explodes when trying to execute business-level code that uses DbContext to access the database with an error: a line with the name "MyEntity" cannot be found in the application configuration file. I tried to define the MyEntity connection string in the MVC project config.json, appsettings.json in different ways, no luck.
If you use business-level methods from the tester project, where I have the expected app.config file with the connection string syntax as shown below, this is not a problem.
Note This question could also be reformulated as porting an MVC 5 application to MVC 6, where access to a weak database connection with MVC 5 to the DAL layer and the MVC code did not know about EF and ONLY supplied the web.config connection string needed by the DbContext object in the DAL?
Any help would be appreciated, let me know if you need more information.
The syntax of the configuration file in the Tester project is:
<add name="MyEntity" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MyServer;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Probable incorrect syntax in config.json file.
{ "Data": { "defaultConnection": { "connectionString": "metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MyServer;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" }, "entityFramework": { "MyEntity": { "ConnectionString": "name=data:defaultConnection:connectionString" } } } }
source share