问题描述
我已经花了更多的时间来进行谷歌搜索,以解决这个问题。我在这个问题上发现的每篇文章似乎都有同样的解决方案。将连接字符串放在启动项目的配置文件中。
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.
我有两个项目。一个用于EDMX,另一个用于网站项目。我有两个文件中的连接字符串,我仍然收到错误。我已经尝试过涉及操纵配置文件的一切工作。我已经尝试将连接字符串放在我的解决方案中的所有配置文件中,删除或添加Entity Framework配置部分到配置文件,并使用nuget卸载和重新安装EF 5。
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.
我继承了这个解决方案,所以我不太了解它是如何创建的,而不是Database First。
I inherited this solution, so I don't know much else about how it was created, other than it was Database First.
连接字符串
<add name="StoreContext" connectionString="metadata=res://*/Store.csdl|res://*/Store.ssdl|res://*/Store.msl;provider=System.Data.SqlClient;provider connection string="data source=*****;initial catalog=*****;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
错误:
No connection string named 'StoreContext' could be found in the application config file.
推荐答案
我一直在那里,挣扎着那个确切的问题。
I've been there and struggled with that exact issue.
解决方案是使用 NuGet 将Entity Framework 6添加到应用程序中。这将为您自动生成正确的连接字符串,并且完全自动设置您的app.config 。
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.
设置app.config的NuGet向导是非常聪明的:如果它已经有一些坏的设置,它将删除它们并添加好的条目。
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.
这篇关于在配置文件中不能找到连接字符串。但它在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!