[解决]在运行时通过实体框架连接到SQLite的麻烦 [英] [Solved] Connecting to SQLite via entity framework at runtime trouble

查看:54
本文介绍了[解决]在运行时通过实体框架连接到SQLite的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用sity作为数据库的项目实体框架。我需要让用户在运行时选择他们的文件,我认为我把它全部平方。但是,当我构造我的EF实体对象时,它会引发异常,我无法弄清楚我缺少的是什么。

  string  connection =  String  .Format(  metadata = res://*/MyData.csdl | res://*/MyData.ssdl | res://*/MyData.msl; provider = System.Data.SQLite; provider connection string =& quot; data source = {0}& quot;,file); 
_data = new MyDataEntities(connection);



我得到异常:不支持关键字:'数据源'。



更新

由OP自己解决。张贴作为答案。

解决方案

好的我发现了我的问题。我直接从app.config中删除了我的连接字符串。罪魁祸首是它出现在两个地方。将其更改为'data source = {0}'解决了这个问题。


你能不能写出所需的最终连接字符串?

我遇到同样的问题。

I am using Entity framework for my project with sqlite as the database. I need to let the user choose their file at run time, and I would think that I have it all squared away. However when I construct my EF entities object it throws an exception and I can't figure out what I am missing.

string connection = String.Format("metadata=res://*/MyData.csdl|res://*/MyData.ssdl|res://*/MyData.msl;provider=System.Data.SQLite;provider connection string="data source={0}"", file);
_data = new MyDataEntities(connection);


I get the exception: "Keyword not supported: 'data source'."

UPDATE:
Solved by OP himself. Posted as an answer.

解决方案

Ok I found my problem. I coppied my connection string straight from an app.config. The culprit was the " in the two places it was showing up. Changing it to 'data source={0}' solved the issue.


can you please write the final connection string needed?
im in the same problem..


这篇关于[解决]在运行时通过实体框架连接到SQLite的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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