在应用程序配置文件中找不到名为'MyAppDbContext'的连接字符串

问题描述:

在我的DAL项目中我有从ii使用的存储库。我已经重构项目有点和现在收集来自库我收到提示在应用程序配置文件中找不到名为'MyAppDbContext'的连接字符串

数据“没有连接字符串名为‘MyAppDbContext’可以在 应用程序配置文件中找到。”

  • 为什么我收到此错误信息:

我在那里生活的仓库有以下方面

<?xml version="1.0" encoding="utf-8"?> 
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />  
    </configSections> 
    <connectionStrings> 
    <add name="MyAppDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyApp.DAL.MyAppDbContext;Integrated Security=True;AttachDBFilename=MyApp.DAL.MyAppDbContext.mdf" providerName="System.Data.SqlClient" />    
    </connectionStrings> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

其实我有两个问题上的App.config同一项目(DAL): “在应用程序配置文件中找不到名为'MyAppDbContext'的连接字符串。”

  • 如何在conn中设置路径。字符串从App_Data目录使用db(在我将它移动到此处之后)
  • +0

    你是什么意思“使用数据库从App_Data”?使用存储在那里的连接字符串? –

    +0

    我希望物理上将db移动到App_Data并在conn中设置此位置。串。 – user1765862

    +0

    @ user1765862查看ms sql compact edition或sqlite。我认为这将是更好的解决方案本地数据库在App_Data –

    尝试将连接字符串添加到耗用项目的配置文件中,而不是DAL项目。

    +0

    这太奇怪了。它也适用于我,但为什么?如果我只有一个项目,数据模型定义,并且没有其他主要的可执行项目呢? –

    +0

    @AndyJ,不知道,但它是什么。加载数据模型和执行代码需要一些可执行文件或主项目,默认情况下配置来自该项目。你的数据模型不能执行,所以这种情况不能存在! –