[英]Why do I get this error when I try to open an MDF database via path/filename in Entity Framework?
I'm migrating an application from LINQ-to-SQL to Entity Framework and have changed the line: 我正在将应用程序从LINQ-to-SQL迁移到Entity Framework ,并更改了这一行:
using (var db = new MainDataContext(SystemHelpers.GetDatabaseConnectionString()))
to 至
using (var db = new MainDataEntities(SystemHelpers.GetDatabaseConnectionString()))
where SystemHelpers.GetDatabaseConnectionString())
is a file path to an .mdf file . 其中
SystemHelpers.GetDatabaseConnectionString())
是.mdf文件的文件路径 。
It works in LINQ-to-SQL but in Entity Framework the above line gives me this error : 它在LINQ-to-SQL中有效,但在Entity Framework中,上一行给我这个错误 :
The format of the initialization string conflicts with the specification which begins with '0';
初始化字符串的格式与以“ 0”开头的规范冲突。
which is the best translation I can do from the German: 这是我能用德语做的最好的翻译:
"Das Format der Initialisierungszeichenfolge stimmt nicht mit der Spezifikation überein, die bei Index '0' beginnt."
“从最初的索引“ 0”开始,就可以在Spezifikationüberein中进行初始化。”
Entity Framework connections string are more complicated than standard connection strings. 实体框架连接字符串比标准连接字符串复杂。
They are made up of three parts: 它们由三部分组成:
Here is what it one might look like: 这可能是这样的:
metadata=res:// /Model.csdl|res:// /Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True" 元数据= res:// /Model.csdl|res:// /Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider连接字符串=“ Data Source =。\\ SQLEXPRESS;初始目录=数据库;集成安全性=真;池=假; MultipleActiveResultSets =真”
Hope this helps 希望这可以帮助
Alex 亚历克斯
EF connection strings can't be the DB connection string alone. EF连接字符串不能仅是数据库连接字符串。 They contain the DB connection string, but they have much more information, too.
它们包含数据库连接字符串,但也有更多信息。 It sounds like you're trying to use the DB connection string alone.
听起来您正在尝试单独使用数据库连接字符串。 That won't work.
那行不通。 See this example for how to build an EF connection string .
有关如何构建EF连接字符串的信息,请参见此示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.