实体框架在 Visual Studio 中丢失与连接字符串的绑定
我遇到一个问题,实体框架 edmx 文件显然失去了与其构建的连接字符串的关系。
我的 .edmx 文件的设计器工作得很好 - 我可以执行“从数据库更新”,它总是会跳转到允许我添加表、过程等的向导步骤。现在,当我单击“从数据库更新”时,我收到“选择您的数据连接”向导步骤,它希望我选择一个新数据库 - 如果我完成这些步骤,它将为我创建一个新的连接字符串,并重新生成所有对象,就像我从划痕。
我的 app.config 文件的内容与问题发生之前完全相同,但我确实修改了该文件,然后将其恢复为原来的样子。我在想以某种方式修改这个文件会触发一些导致我失去绑定的东西,但我不知道那是什么。
配置文件中的连接字符串键与 EDMX 文件中的 CdmEntityContainer 属性匹配。
我什至尝试删除我的代码库并从源代码管理中重新签出,但这似乎不起作用。在同一代码库上工作的其他人也遇到了同样的问题,因此项目中的某个地方似乎肯定有问题。但 .csproj 或 .sln 文件没有相关更改 - 只是我在任何地方都看不到可能导致此问题的地方。
有什么想法吗?我现在看到的唯一解决方案是从头开始删除并重新创建 edmx 文件,但我绝对希望找到更好的东西。
编辑:如果我在项目中生成一个全新的 edmx,与任何现有的无关,它似乎可以修复其余的问题。它必须“重置”项目中任何时髦的东西。但这不是一个合法的解决方案,所以我仍然希望有更好的解决方案。
I'm having a problem where the Entity Framework edmx file is apparently losing its relationship to the connection string that it was built with.
The designer for my .edmx file was working perfectly - I could do "Update from database" and it would always jump to the wizard step that would allow me to add tables, procs, etc. Now when I click "Update from database", I get the "Choose your data connection" wizard step where it wants me to select a new database - if I go through these steps, it will create a new connection string for me, and regenerate all of the objects as if I was starting from scratch.
The contents of my app.config file are exactly as they were prior to the problem, but I did modify the file, then revert it back the way it was. I'm thinking somehow modifying this file triggers something that causes me to lose the binding, but I can't figure out what that is.
The connection string key in the config file matches the CdmEntityContainer attribute in the EDMX file.
I've even tried killing my codebase and re-checking-out from source control, but that doesn't seem to work. Other people working on the same codebase are having this same problem, so it seems that there's something definitely wrong somewhere in the project. But there were no relevant changes to the .csproj or .sln files - just nothing I can see anywhere that could be causing this.
Any ideas? The only solution I'm seeing right now is to delete and recreate the edmx files from scratch, but I'm definitely hoping to find something better.
EDIT: If I generate a brand new edmx in the project, unrelated to any of the existing ones, it seems to fix the rest. It must "reset" whatever is funky in the project. But this can't be a legitimate solution, so I'm still hoping for something better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
缺少application name=EntityFramework
我刚刚遇到这个问题,在我的连接字符串中,我在数据源中
I just had this issue and in my connection string I was missing
application name=EntityFramework in the data Source
我在将 VS2022 版本 17.4.4 更新到版本 17.5.1 时遇到了这个问题
我尝试了一切方法来修复它,但直到我降级到 17.4.4 之前的版本时才知道它的版本问题。
您可以从以下网站找到以前的版本。在安装以前的版本之前,请确保先卸载当前版本。
Visual Studio 2022 发布历史记录
I faced this problem while I updated VS2022 version 17.4.4 to version 17.5.1
I tried everything to fix it and didn't know its the version problem until I downgraded to pre version which was 17.4.4.
you can find former releases from the below web. before installing former version make sure you uninstalled the current version first.
Visual Studio 2022 Release History
我刚刚遇到了这个并解决了它。
问题是 edmx 被用作我的 DAL,有它自己的项目和 Web 配置,并且 DAL 由我的 ASP.NET 项目(解决方案的默认项目)使用 ITS 自己的 Web 配置调用。
配置多年来一直保持不变,但 ASP.NET 项目被指向另一台服务器(即连接字符串已更改)。即使 DAL 的连接字符串仍然保持不变、有效,并且当您想要在设计时“从数据库更新模型”时,不涉及 ASP.NET 项目,但它一定与默认项目冲突有关。
我将包含 edmx 的项目的 Web 配置中的 connstring 更改为与默认项目的相同,并且它再次工作。
I just had this and solved it.
The problem was that the edmx was being used as my DAL, with its own project and web config, and the DAL was called by my ASP.NET project (the solution's default project) with ITS own web config.
The configs had been the same for ages, but the ASP.NET project was pointed to another server (ie the connection string changed). Even though the DAL's connection string was still unchanged, valid and the ASP.NET project wasn't involved when you want to "Update model from database" at design time, it must be something to do with the default project clashing with it.
I changed the connstring in the web config of the project containing the edmx to be the same as the default project's one, and it worked again.
如果您恰好在环境(例如开发、生产)之间切换时出现此问题,并且您在这些环境中运行不同的 SQL Server 版本(例如 2005、2008),则可能会遇到一些问题。数据库版本号存储在 .edmx 文件中的某个位置。
如果是这样,请告诉我,我可以挖掘具体细节并做出回应。如果不是,我不知道它会是什么。
祝你好运!
编辑:我意识到这可能与实际问题无关,但我想提供我提到的具体细节,以防其他人遇到这个问题。
Schema
元素(.edmx 内)中的ProviderManifestToken
属性包含数据库版本号。请注意,它实际上使用年份(例如 2005、2008)而不是真正的数据库版本号。如果您在一个版本上创建模型并将其移动到另一版本,则需要手动编辑文件以更改此值。If you happen to be bouncing between environments (e.g. dev, prod) when this problem popped up and you are running different SQL Server version (e.g. 2005, 2008) in those environments, you can have some problems. The DB version number gets stored somewhere in the .edmx file.
If that is the case, let me know and I can dig up the specifics and respond with them. If not, I don't know what it could be.
Good luck!
EDIT: I realize this probably has nothing to do with the actual problem, but I wanted to provide the specifics I mentioned in case someone else runs across this. The
ProviderManifestToken
attribute in theSchema
element (inside the .edmx) contains the database version number. Note that it actually uses the year (e.g. 2005, 2008) instead of the true DB version number. If you create a model on one version and move it to another version, you'll need to manually edit the file to change this value.老问题,但我想我会发布对我有用的修复程序,供那些仍然遇到此问题的人使用。就我而言,这只是一个密码问题。我正在测试中工作,但连接字符串正在使用生产密码。 VS 更有用的响应可能是显示“无效的登录名或密码”类型的消息,因为这实际上是问题所在。
Old question but I thought I would post the fix that worked for me for those who still have this problem. In my case, it was simply a password issue. I was working in test, but the connection string was using the password for production. A more helpful response by VS might be to display an "Invalid login or password" type of message since that was actually the problem.
我能够通过修改 edmx 使用的连接字符串来解决此问题,不使用集成安全性,而是使用用户名和密码。
I was able to resolve this issue by modifying my connection strings used by the edmx to NOT use integrated security and instead use a username and password.