在LocalDB + EntityFramework的配置错误中找不到指定的命名连接

时间:2013-08-12 11:50:58

标签: c# entity-framework sql-server-ce

尝试单独进行连接,但是它一直坚持无法找到连接。

我的配置文件:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <connectionStrings>
    <add name="Tank_Analizor_DBEntities" connectionString="metadata=res://*/Analizor.csdl|res://*/Analizor.ssdl|res://*/Analizor.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=|DataDirectory|\DB\Tank_Analizor_DB.sdf&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

尝试直接将路径更改为数据库文件,例如:

    <add name="Tank_Analizor_DBEntities" connectionString="metadata=res://*/Analizor.csdl|res://*/Analizor.ssdl|res://*/Analizor.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=C:\Debug\DB\Tank_Analizor_DB.sdf&quot;" providerName="System.Data.EntityClient"/>

但仍然没有运气,这可能是什么问题?

1 个答案:

答案 0 :(得分:0)

更新实体框架连接工厂设置。您是指向sql server compact的连接字符串,但是为sql server v11.0配置了连接工厂

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="System.Data.SqlServerCe.4.0" />
    </parameters>
  </defaultConnectionFactory>
</entityFramework>