MVC "Add Controller" - "Cannot get metadata ... System configuration could not be initialized"

From scratch, I made a new solution with two projects: one was MVC 3, and the other was an EF 4.2 supporting project. All this is being built successfully. From the MVC project, I open the "Add Controller" dialog and generate code based on the context and model that I select from the supporting EF project. The "add controller" dialog ends with the message:

Unable to retrieve metadata for "MyModelClass". Failed to initialize configuration system.

I noticed that the “add controller” dialog is actually trying to get the database connection string from the web.config file. Firstly, it looks like goofy-ish, since the supporting EF project already has app.config with a connection string. But, ignoring this, the best thing I can understand is that the connection string in web.config is bad. It looks like this:

<add name="Monsters2Entities" connectionString=" metadata=res://*/Monsters.csdl| res://*/Monsters.ssdl| res://*/Monsters.msl; provider=System.Data.SqlClient; provider connection string=&quot; data source=.; initial catalog=Monsters2; integrated security=True; pooling=False; multipleactiveresultsets=True; App=EntityFramework &quot;" providerName="System.Data.EntityClient" /> 

There are virtually no ridiculous line breaks and indents in the connection string — I'm just trying to make it easier to read. In any case, this connection string is basically identical to the connection string used in the supporting EF project on which it is being modeled. How do I fix this to make the add controller dialgoue happy?

+10
visual-studio asp.net-mvc entity-framework
Nov 23 '11 at 7:55
source share
11 answers

I installed EF 6, which added:

 <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> 

In my configuration file. I had other problems with the forests, so I decided to return to Ef 5. After uninstalling EF 6 and reinstalling EF 5, I removed it from the config and then was able to build my new controller. I discovered this with

 PM> Update-Database –Verbose 
+8
Nov 21 '13 at 19:35
source share

Just copy the connection string information from the EF model App.Config project into your file and see that you are not repeating any sections (for example, the entityFramework section)

  

+2
Nov 27 '12 at 9:17
source share

Try the following:

 <add name="Monsters2Entities" connectionString=" metadata=res://*/Monsters.csdl| res://*/Monsters.ssdl| res://*/Monsters.msl; provider=System.Data.SqlClient; provider connection string=' data source=.; initial catalog=Monsters2; integrated security=True; pooling=False; multipleactiveresultsets=True; App=EntityFramework '" providerName="System.Data.EntityClient" /> 

I replaced &quot; on '

+1
Nov 23 '11 at 16:15
source share

I added this to my Global.Asax file so that: a) the database is started immediately and b) a table definition is added. letting the controller find the table definition:

  System.Data.Entity.Database.SetInitializer<ProjectName.DAL.DBConnectContextName>(new CreateDatabaseIfNotExists<ProjectName.DAL.DBConnectContextName>()); 
+1
Sep 30 '14 at 10:04
source share

I found that it helped when I had this problem:

Removed the preliminary version of EF and installed EF5. I went to Sql Server Object Explorer and deleted db. Restored solution used by PM> Update-Database-Verbosa

Perhaps the problem was a preliminary release of EF or just clearing the sky.

I am completely new to everyone, but it allowed me to use the Add Controller scaffolding tool with the help of "MVC-controller with checking and recording actions and reviews using the Entity Framework template".

0
Dec 27 '12 at 12:48
source share

First of all, you should check that your connection string should be in your Web.Config file in ROOT! of your project after this check, if there is another connection string or not, if there is another connection string, replace it with the connection string. This solved my problem, which was the same as yours ....

0
Mar 18 '13 at 7:56
source share

I managed to solve my problem by changing the edmx code generation strategy to T4, adding the Eb5 Db context and replacing% edmxInputFile% in the * .tt and * .Context.tt files.

0
Feb 13 '14 at 2:36 on
source share

Rename the Model class - worked for me

0
Mar 30 '14 at 23:04
source share

Do you have a ConnectionString file in your Web.Config file before creating a controller? Sometimes we create another project containing the Entity Entity Context, and we forgot to add the same connectionString to Web.Config inside another project.

 <connectionStrings> <add name="Monsters2Entities" ... /> </connectionStrings> 
0
Jul 03 '14 at 8:33
source share

I am facing this problem "Unable to retrieve metadata ..." until I used the controller. The solution for this is as follows.

  • In the Application Connection String change to "system.data.sqlclient" 2.or Remove the connection string from Web.config and add the controller and after adding the controller add the connection string again.

This seems to be a bug in MVC. I hope you can continue with this.

0
Aug 31 '16 at 18:50
source share

you must first install the package entity infrastructure

go to tool> Libray Package Manager> pakage manager console>: set entity structure

-one
Aug 27 '12 at 18:13
source share



All Articles