No connection string named "NorthwindConnection" could be found in the application config file

c# entity-framework

Question

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>
1
2
8/30/2014 1:28:46 PM

Accepted Answer

Try copying the connections string to the .config file in the MVC project.

305
9/27/2012 1:25:05 PM

Popular Answer

You are right, this happens because the class library (where the .edmx file) is not your startup / main project.

You'll need to copy the connection string to the main project config file.

Incase your startup / main project does not have a config file (like it was in my Console Application case) just add one (Startup project - Add New Item -> Application Configuration File).

More relevant information can be found here: MetadataException: Unable to load the specified metadata resource



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow