【问题标题】:MVC error with Database Entities数据库实体的 MVC 错误
【发布时间】:2014-12-26 11:12:49
【问题描述】:

大家好,我目前正在做一个 MVC 项目我有以下错误,这是我正在做的一个多层项目

EntityFramework.dll 中出现“System.InvalidOperationException”类型的异常,但未在用户代码中处理附加信息:在应用程序配置文件中找不到名为“AssignmentEntities”的连接字符串。

现在我已将连接字符串从公共层复制到应用层,但我仍然收到错误消息。你认为是什么错误?

这是 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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="AssignmentEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=mathis;initial catalog=&quot;&quot;Trader'sMarketplace&quot;&quot;;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

这是 web.config 文件

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<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="AssignmentEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=mathis;initial catalog=&quot;&quot;Trader'sMarketplace&quot;&quot;;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IProductsBL" />
        <binding name="BasicHttpBinding_IUserBL" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:63717/ProductsBL.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProductsBL" contract="ProductsService.IProductsBL" name="BasicHttpBinding_IProductsBL" />
      <endpoint address="http://localhost:63717/UserBL.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserBL" contract="UsersService.IUserBL" name="BasicHttpBinding_IUserBL" />
    </client>
  </system.serviceModel>
</configuration>

感谢您的帮助,因为我在过去几天一直在尝试解决此问题,但无处可寻。

【问题讨论】:

    标签: c# asp.net-mvc database entity-framework visual-studio-2013


    【解决方案1】:

    确保您已将更改保存在 Web.config(如果您有 Web 应用程序)或 App.config(如果您有桌面应用程序)中。


    错误提示:No connection string named 'AssignmentEntities' could be found in the application config file

    您必须修改启动项目的配置。

    【讨论】:

      【解决方案2】:

      所以我已经解决了这个问题,我遇到的问题是在我用于服务引用的 BL-Services 库中没有连接字符串。在过去的几天里,我一直在敲我的头,一无所获。现在我可以说它有效了。

      【讨论】:

        猜你喜欢
        • 2014-10-24
        • 2015-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-11
        • 1970-01-01
        相关资源
        最近更新 更多