不支持关键字:“数据源”初始化实体框架上下文 [英] Keyword not supported: "data source" initializing Entity Framework Context

查看:154
本文介绍了不支持关键字:“数据源”初始化实体框架上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在初始化Entity Framework Object上下文,这给了我不支持的关键字错误:



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



我直接从web.config正在工作的连接字符串,并修改了文件的路径(我动态设置),而是使用默认值,显式地使用这个连接字符串。可能会导致此错误?

解决方案

您收到此错误的真正原因是因为& ;



如果您用单引号替换,那么它可以正常工作。



http ://blogs.msdn.com/b/rickandy/archive/2008/12/09/explicit-connection-string-for-ef.aspx




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?

解决方案

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.

http://blogs.msdn.com/b/rickandy/archive/2008/12/09/explicit-connection-string-for-ef.aspx

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

这篇关于不支持关键字:“数据源”初始化实体框架上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆