没有名为'KgSoftProContext'可以在应用程序配置文件中找到

本文关键字:配置文件 应用程序 KgSoftProContext | 更新日期: 2023-09-27 18:09:13

我已经在项目数据库中添加了DLL。主句,即使在配置文件中的连接将其添加到项目,我得到这个错误。

数据库dll配置文件

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
</configuration>

主项目app.config文件

<connectionStrings>
    <add name="KgSoftProContext" connectionString="Data Source=KDRGNY'KDRGNY;Initial Catalog=KgSoftPro;Integrated Security=True;MultipleActiveResultSets=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

上下文文件

 static KgSoftProContext()
        {
            Database.SetInitializer<KgSoftProContext>(null);
        }
        public KgSoftProContext()
            : base("name=KgSoftProContext")
        {
        }

没有名为'KgSoftProContext'可以在应用程序配置文件中找到

已经失控了,我正试着彻底解决这个问题。问题解决了

将连接字符串部分复制到主项目的.config文件中。