不支持关键字:“数据源”初始化实体框架上下文
我正在初始化实体框架对象上下文,这给了我关键字不支持的错误:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您收到此错误的真正原因是连接字符串中的
"
值。如果将它们替换为单引号,那么它会正常工作。
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.)
即使我使用的是实体框架,我也通过将
EntityClient
更改回SqlClient
来修复此问题。所以我的完整连接字符串的格式为:
I fixed this by changing
EntityClient
back toSqlClient
, even though I was using Entity Framework.So my complete connection string was in the format:
这似乎缺少
providerName="System.Data.EntityClient"
位。你确定你掌握了全部内容吗?This appears to be missing the
providerName="System.Data.EntityClient"
bit. Sure you got the whole thing?不管你相信与否,将 LinqPad.exe.config 重命名为 LinqPad.config 解决了这个问题。
Believe it or not, renaming LinqPad.exe.config to LinqPad.config solved this problem.
确保连接字符串中有
Data Source
而不是DataSource
。空间很重要。相信我。我是个白痴。Make sure you have
Data Source
and notDataSource
in your connection string. The space is important. Trust me. I'm an idiot.只需使用 \" 而不是 ",它应该可以解决问题。
Just use \" instead ", it should resolve the issue.