Keyword not supported: “data source” initializing Entity Framework Context

独自空忆成欢 提交于 2019-12-28 02:28:05

问题


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?


回答1:


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.)




回答2:


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" />



回答3:


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




回答4:


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




回答5:


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




回答6:


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



来源:https://stackoverflow.com/questions/6997035/keyword-not-supported-data-source-initializing-entity-framework-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!