1
我在項目數據庫中添加了DLL。主語句即使配置文件中的連接將其添加到項目我收到此錯誤。在應用程序配置文件中找不到名爲'KgSoftProContext'的連接字符串
數據庫的DLL app.config文件
<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")
{
}
將連接字符串部分複製到主項目中的.config文件。 –
@ rory.ap - 主項目代碼的第二段屬於。 –