0

I am just starting to get started with MVC6 and I can't find a simple explanation to a problem I have.

My MVC6 web app has a reference to a .NET business layer, and this references a .NET data layer.

The data layer is looking for a connection string (let's call it XXXX) in the web.config:

<configuration>
  <connectionStrings>
    <add name="XXXX" connectionString="metadata=res://*/XXXX.csdl|res://*/XXXX.ssdl|res://*/XXXX.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=XXXX;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
</configuration>

MVC6 does not have a web.config (in the traditional sense). I have tried to add a connection string to the appsettings.json file, and try to set up the startup.cs file so it references the same name, but each time I try to run it I get an error:

InvalidOperationException: No connection string named 'XXXX' could be found in the application config file.

Can someone give me some straightforward instructions so my appsettings.json and startup.cs can pass a XXXX connection string to my data layer?

Nigel Ellis
  • 601
  • 1
  • 8
  • 18
  • Look at [the answer](http://stackoverflow.com/a/34376614/315935) or you can download the demo project form the beginning of **UPDATED** part of [another answer](http://stackoverflow.com/a/34556712/315935). – Oleg Jan 17 '16 at 00:05
  • @Oleg I don't think I explained this properly - there is some information I probably should have included. My business and data layer are existing class libraries from a .NET 4 solution (which has a MVC 4/5 web layer). The class libraries are using EF6. If I have to create/upgrade my business and data layers I will, but I am trying to use them in their existing forms. – Nigel Ellis Jan 17 '16 at 11:41
  • I don't recommend you to try to mix old components with new MVC6. You will spend a lot of time to make it working, but your application will have no advantage of new ASP.NET 5. – Oleg Jan 17 '16 at 11:46
  • That's what I am starting to learn - the hard way :) I was trying to use the existing layers as they are working - and learn MVC6. Looks like upgrading/redoing my layers is needed. Lesson learned. – Nigel Ellis Jan 17 '16 at 11:48
  • EF7 is redesigned to remove all XML configuration. Many parts of code are rewritten in MVC6 and EF7, some old parts are not yet implemented and so on. The best results you could get in the future if you would develop using `dnxcore50` and not only `dnx451`, but some parts which you need is not yet. I would recommend you [the article](https://docs.asp.net/projects/mvc/en/latest/migration/index.html) and [this one](http://docs.efproject.net/en/latest/getting-started/aspnet5/existing-db.html). Be not so hurry in migration of complex EF6 application, just start to study new EF7 and MVC6. – Oleg Jan 17 '16 at 11:57
  • Thanks for the links. The app I am trying to *upgrade* is my own website. It has a lot of code, but it's not complex. It's mostly fetching data and saving it back. My database is messy so I planned to rewrite my database - I might do that sooner rather than later. I am hoping to run into these problems first before I do try to upgrade a complex project. – Nigel Ellis Jan 17 '16 at 12:01
  • OK, then rewriting of the code to new MVC6/EF7 could be the best choice for you. You should just go through the tutorials with existing database and create one simple application. Then you can extend it, after you good understand how the new concept work. If you would have some problem later, you can upload the whole test project somewhere and ask new question. It allows other to reproduce your problem immediately and to help you. Best wishes! – Oleg Jan 17 '16 at 12:05
  • If you really want to use EF6 then you can look [here](https://github.com/OneBitSoftware/Microsoft.AspNet.Identity.EntityFramework6), [here](https://github.com/entrypointsoft/AspNet.Identity.EntityFramework6), [here](https://github.com/staff0rd/Identity/tree/dev/src/Microsoft.AspNet.Identity.EntityFramework6) and other. – Oleg Jan 17 '16 at 12:12

0 Answers0