2

I have 2 projects: Console app and dll. In dll i am using EntityFramework. I have this app.config file:

<?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>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
      <connectionStrings>
        <add name="NorthwindConnection" connectionString="Data Source=ВЛАДИСЛАВ-ПК\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa;" providerName="System.Data.SqlClient" />
      </connectionStrings>
    </configuration>

I am calling EntityFramework from console app, but i have this error message: "No connection string named "NorthwindConnection" could be found in the application config file.".

This is console app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
BJladu4
  • 263
  • 4
  • 15
  • 1
    Found the solution! I added EF references both to console app and to dll, deleted app.config from dll and added app.config to console app and write there data from first code block wrote above. – BJladu4 Aug 30 '14 at 14:08

1 Answers1

1

Copy following tag from your .dll config file into your console project app.config:

  <connectionStrings>
    <add name="NorthwindConnection" connectionString="Data Source=ВЛАДИСЛАВ-ПК\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa;" providerName="System.Data.SqlClient" />
  </connectionStrings>

So your app.config in your console project will be:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="NorthwindConnection" connectionString="Data Source=ВЛАДИСЛАВ-ПК\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;Password=sa;"   providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>
Masoud
  • 8,020
  • 12
  • 62
  • 123