当我尝试通过实体框架中的路径/文件名打开MDF数据库时,为什么会收到此错误? [英] Why do I get this error when I try to open an MDF database via path/filename in Entity Framework?

查看:208
本文介绍了当我尝试通过实体框架中的路径/文件名打开MDF数据库时,为什么会收到此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将应用程序从LINQ到SQL迁移到实体 框架,并更改了以下行:

  using(var db = new MainDataContext(SystemHelpers.GetDatabaseConnectionString()))


$使用(var db = new MainDataEntities(SystemHelpers.GetDatabaseConnectionString()))


   

其中 SystemHelpers.GetDatabaseConnectionString())是一个文件路径到.mdf文件



它适用于LINQ到SQL,但在实体框架中,上面的一行给了我这个错误


初始化
字符串的格式与以$ 0开头的
规范冲突, ;


这是德文可以做的最好的翻译:


Das Format der
Initialisierungszeichenfolge stimmt $ b $


解决方案



它们由三部分组成:


  1. 提供者连接字符串=>
    这是您提供的

  2. 元数据=>哪里是
    EF应从(即。)获得CSDL,MSL和
    SSDL概念模型,
    映射和存储模型)

  3. 提供者名称=> ie为SQL
    服务器这通常是
    System.Data.SqlClient

这是一个可能的样子:



metadata = res:/ //Model.csdl|res:///Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string =Data Source = .\\ \\ SQLEXPRESS;初始目录=数据库;集成安全= True; Pooling = False; MultipleActiveResultSets = True



希望这有助于



Alex


I'm migrating an application from LINQ-to-SQL to Entity Framework and have changed the line:

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.

It works in LINQ-to-SQL but in Entity Framework the above line gives me this error:

The format of the initialization string conflicts with the specification which begins with '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."

解决方案

Entity Framework connections string are more complicated than standard connection strings.

They are made up of three parts:

  1. the Provider Connection String => this is what you're providing
  2. the Metadata => which is where the EF should get the CSDL, MSL and SSDL from (i.e. Conceptual Model, Mapping and Storage Model)
  3. the Provider name => i.e. for SQL server this is generally System.Data.SqlClient

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"

Hope this helps

Alex

这篇关于当我尝试通过实体框架中的路径/文件名打开MDF数据库时,为什么会收到此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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