没有名为'MyAppDbContext“连接字符串可能会在应用程序配置文件中找到 [英] No connection string named 'MyAppDbContext' could be found in the application config file

查看:401
本文介绍了没有名为'MyAppDbContext“连接字符串可能会在应用程序配置文件中找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的DAL项目,我有我从UI消耗库。我已经重构项目了一下,现在开始收集来自库中我得到的数据误差

Inside my DAL project I have repositories which I consume from ui. I've refactor project a bit and now on gather data from repository I'm getting error

没有名为'MyAppDbContext可能连接字符串在
应用程序配置文件中找到。

"No connection string named 'MyAppDbContext' could be found in the application config file."

我的App.config中对同一项目(DAL),其中库生活有以下上下文

My App.config on same project (DAL) where repository lives have following context

<?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>



其实,我有两个问题:

I actually have two questions:


  • 为什么我收到此错误信息:没有名为MyAppDbContext可能会在应用程序配置文件中找到连接字符串

  • 如何设置路径连接中。字符串使用DB从App_Data目录(之后我移动它有ofcourse)

推荐答案

尝试添加连接字符串的消费项目,而不是DAL项目的配置文件。

Try adding connection string to the configuration file of the consuming project, not the DAL project.

这篇关于没有名为'MyAppDbContext“连接字符串可能会在应用程序配置文件中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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