简体   繁体   中英

No connection string could be found in the config file. But it is there

I have spent the better part of the day googling for a fix to this. Every post I have found on this problem seems to have the same solution. Put the connection string in the config file for the start up project.

I have two projects. One for the EDMX and one for the website project. I have my connection string in both files, and I still receive the error. I have tried everything involving manipulating the config files to get this to work. I have tried putting the connection string in all the config files in my solution, removing or adding the Entity Framework config section to the config files, and Uninstalling and re-installing EF 5 using nuget.

I inherited this solution, so I don't know much else about how it was created, other than it was Database First.

connection string

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

Error:

No connection string named 'StoreContext' could be found in the application config file.

I've been there and struggled with that exact issue.

The solution is to add Entity Framework 6 to your application using NuGet . This will auto generate the correct connection string for you, and automatically set up your app.config perfectly.

The NuGet wizard that sets up app.config is quite smart: if there are some bad settings in it already, it will remove them and add good entries.

For more details, and a step-by-step guide, see my answer at: Upgrade from Entity Framework 5 to 6 .

Try this: - Delete (or comment out) the connection string in web.config - Delete the model.tt file nested in the edmx - Double click the edmx file and right click in a blank space and "Update Model from Database". This will ask you for a new connection string.

If you do not delete the original, you cannot complete the wizard.

Alternatively, upgrade to 6.1 and your troubles will go away.

I would check to ensure that the connection string in the start up project is correct. This is usually where I get this same error, and it is almost always fixed by copying the connection string from the Data project with the EDMX to the start up project.

I would also suggest to check that you're importing the reference to the EDMX project, but I think if you're getting as far as the error you're describing, then you're already doing that.

One more thing that I've seen before is that you need to get the Entity Framework for both projects. The other day I had an issue similar to this (can't remember the exact error) where installing EF to the startup project fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM