不支持关键字:“数据源”初始化实体框架上下文

发布于 2024-11-28 19:27:51 字数 401 浏览 2 评论 0原文

我正在初始化实体框架对象上下文,这给了我关键字不支持的错误:

metadata=res://*/MainDB.csdl|res://*/MainDB.ssdl|res://*/ MainDB.msl;provider=System.Data.SqlClient;提供者连接字符串="数据Source=.\SQLEXPRESS;AttachDbFilename=D:\Workspace\vs\Leftouch\Leftouch.Web\Data\Leftouch.mdf;集成安全性=True;连接超时=30;用户实例=True;App=EntityFramework"

我直接从正在运行的 web.config 获取连接字符串,并仅修改文件的路径(我动态设置),而不是使用默认值,而是使用此连接显式地字符串。什么可能导致此错误?

I'm initializing Entity Framework Object context, and this gives me the keyword not supported error:

metadata=res://*/MainDB.csdl|res://*/MainDB.ssdl|res://*/MainDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Workspace\vs\Leftouch\Leftouch.Web\Data\Leftouch.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;App=EntityFramework"

I took the connection string directly from web.config which was working, and modified only the path to the file (which I set dynamically), and instead of using the default value, used this connection string explicitly. What could cause this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

撩心不撩汉 2024-12-05 19:27:51

您收到此错误的真正原因是连接字符串中的 " 值。

如果将它们替换为单引号,那么它会正常工作。

https://learn.microsoft.com/archive/blogs /rickandy/explicit-connection-string-for-ef

(发布是为了其他人可以比我更快地获得修复。)

The real reason you were getting this error is because of the " values in your connection string.

If you replace those with single quotes then it will work fine.

https://learn.microsoft.com/archive/blogs/rickandy/explicit-connection-string-for-ef

(Posted so others can get the fix faster than I did.)

预谋 2024-12-05 19:27:51

即使我使用的是实体框架,我也通过将 EntityClient 更改回 SqlClient 来修复此问题。

所以我的完整连接字符串的格式为:

<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx" providerName="System.Data.SqlClient" />

I fixed this by changing EntityClient back to SqlClient, even though I was using Entity Framework.

So my complete connection string was in the format:

<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx" providerName="System.Data.SqlClient" />
孤城病女 2024-12-05 19:27:51

这似乎缺少 providerName="System.Data.EntityClient" 位。你确定你掌握了全部内容吗?

This appears to be missing the providerName="System.Data.EntityClient" bit. Sure you got the whole thing?

a√萤火虫的光℡ 2024-12-05 19:27:51

不管你相信与否,将 LinqPad.exe.config 重命名为 LinqPad.config 解决了这个问题。

Believe it or not, renaming LinqPad.exe.config to LinqPad.config solved this problem.

深爱不及久伴 2024-12-05 19:27:51

确保连接字符串中有 Data Source 而不是 DataSource。空间很重要。相信我。我是个白痴。

Make sure you have Data Source and not DataSource in your connection string. The space is important. Trust me. I'm an idiot.

不及他 2024-12-05 19:27:51

只需使用 \" 而不是 ",它应该可以解决问题。

Just use \" instead ", it should resolve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文