2015-04-26 43 views
2

在我的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 –

    回答

    1

    嘗試將連接字符串添加到耗用項目的配置文件中,而不是DAL項目。

    +0

    這太奇怪了。它也適用於我,但爲什麼?如果我只有一個項目,數據模型定義,並且沒有其他主要的可執行項目呢? –

    +0

    @AndyJ,不知道,但它是什麼。加載數據模型和執行代碼需要一些可執行文件或主項目,默認情況下配置來自該項目。你的數據模型不能執行,所以這種情況不能存在! –

    相關問題