You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在App.Config中找到Inventory_ManagementEntities连接字符串问题

解决“无法在App.Config文件中找到名为'Inventory_ManagementEntities'的连接字符串”错误

我之前在使用Entity Framework设计器时也碰到过一模一样的问题,结合你提供的app.config代码,给你几个实用的排查和解决步骤:

1. 确认设计器所在项目的配置文件是否包含该连接字符串

很多时候我们会把数据访问层和UI层拆分成不同项目,设计器(比如WinForms/WPF的页面设计器)运行时会读取当前UI项目的配置文件,而不是数据层项目的app.config。你需要把数据层里的<connectionStrings>节点完整复制到设计器所在项目的app.config或web.config中。

2. 检查连接字符串的metadata路径是否正确

你的连接字符串里的metadata部分是:

metadata=res://*/Base_Table.csdl|res://*/Base_Table.ssdl|res://*/Base_Table.msl

这里的Base_Table应该对应你的EDMX文件的名称(不包含.edmx后缀)。如果你的EDMX文件实际叫别的名字(比如InventoryModel.edmx),那这里的路径就会出错,导致设计器找不到实体模型。请确认EDMX文件名和metadata里的名称完全一致。

3. 清理重建解决方案,清除缓存

项目编译缓存有时候会导致配置文件读取异常,按以下步骤操作:

  • 右键解决方案 → 清理解决方案
  • 右键解决方案 → 生成解决方案
  • 关闭Visual Studio,删除项目目录下的bin和obj文件夹,然后重新打开VS并尝试打开设计器

4. 验证Entity Framework版本匹配

你的app.config里配置的Entity Framework版本是4.4.0.0:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

请确认你的项目引用的Entity Framework NuGet包版本确实是4.4.0.0。如果版本不匹配,会导致配置解析失败。你可以右键项目 → 管理NuGet程序包,查看已安装的Entity Framework版本。

5. 手动在DbContext构造函数中指定连接字符串

如果以上方法都无效,你可以在你的Inventory_ManagementEntities DbContext类中,显式指定连接字符串名称:

public class Inventory_ManagementEntities : DbContext
{
    public Inventory_ManagementEntities() 
        : base("name=Inventory_ManagementEntities") // 明确指定连接字符串名称
    {
    }

    // 你的DbSet定义...
}

这样设计器在初始化上下文时,会直接使用这个指定的连接字符串,避免自动查找时出现问题。

附上你提供的app.config代码供参考:

<?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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="Inventory_ManagementEntities" connectionString="metadata=res://*/Base_Table.csdl|res://*/Base_Table.ssdl|res://*/Base_Table.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=MOHSINALVI\TESTSERVER;initial catalog=Inventory_Management;user id=sa;password=telco_123;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

内容的提问来源于stack exchange,提问作者Mohsin Raza Alvi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 15:04:09