【问题标题】:No connection string could be found in the application config file在应用程序配置文件中找不到连接字符串
【发布时间】:2015-01-12 07:08:46
【问题描述】:

我创建了一个 Web 应用程序项目(基于实体框架 5.0)。在解决方案中,我在基于 5.0 版的新 .cs 项目中创建了实体数据模型。现在我有 2 个 web.configs(1 个用于 Web 应用程序项目,另一个用于实体数据模型项目),其中我无法访问在 web.config(实体数据模型项目内部)中定义了连接字符串的网页的实体类。现在,我收到错误,因为“在应用程序配置文件中找不到连接字符串”。 如何解决这个问题?

【问题讨论】:

  • 在项目的 web.config 中创建连接字符串
  • 在 web.config 文件中添加 Connectoinstrnig
  • 现在显示-“具有不变名称'System.Data.EntityClient'的ADO.NET提供程序未在机器或应用程序配置文件中注册,或者无法加载。请参阅内部详情例外。”

标签: asp.net entity-framework-5


【解决方案1】:

将连接字符串添加到 web.config,

<!--web.config of the project that is utilizing Entity Framework-->
<connectionStrings>
<add name="YourConnectionName"
    providerName="System.Data.SqlClient"
    connectionString="Server=YourServerNameOrIP; Database=YourDatabaseName;
    Integrated Security=SSPI" />
</connectionStrings>

现在, 指定到 DbContext 的连接字符串

// In the class inheriting from DbContext

namespace Context
{
    public class Dbc : DbContext
    {
        public Dbc() : base("YourConnectionName") { }
        public DbSet<Message> Messages { get; set; }

    }
}

【讨论】:

  • 现在我收到此错误-“无法找到请求的 .Net Framework 数据提供程序。它可能未安装。”
  • 如果这对您有帮助,请告诉我。
  • @Deepak 您需要安装 Microsoft SQL Server Compact 4.0,这将消除错误消息
  • 好的,我明白了。我需要做的就是在连接字符串中指定正确的文件夹路径(在 web.config 中),因为它不存在。谢谢大家的帮助... :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-17
  • 2012-06-14
  • 2016-12-07
  • 2012-09-19
  • 2022-01-11
  • 1970-01-01
  • 2013-03-28
相关资源
最近更新 更多