-1

Error:

No connection string named 'MediaRentalEntities' could be found in the application config file.

My 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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="MediaRentalEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=MediaRental;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

As you can see connection string is clearly there, it has been automatically generated. I can run the program but it constantly shows this error on error list and i'm unable to view designer.

I have found similar questions, but it was mostly about multiple projects, here i have only one solution and one project.

Edit

Constructor in DBContext:

public MediaRentalEntities()
        : base("name=MediaRentalEntities")
    {
}
  • can u share your db context constructor? – sajjad kalantari May 05 '20 at 17:48
  • It should be in the config file of the *running* assembly. – Gert Arnold May 05 '20 at 20:37
  • Check the name of your config file, for WPF I believe that should just be "app.config", and that when your application is built there is a .exe.config file in your /bin/debug folder where the application is running. Given a project named MyApp, producing a MyApp.exe executable, there should be a MyApp.exe.config file generated. If the .exe.config file exists, verify the connection string is appearing there. – Steve Py May 05 '20 at 23:49
  • @xray posted constructor –  May 06 '20 at 13:29
  • @StevePy it is there, but its exactly the same as App.config. And its already compiled, i have issues while in Visual Studio. –  May 06 '20 at 13:31

1 Answers1

0

change your constructor to be like

public MediaRentalEntities()
    : base("MediaRentalEntities")
{}
sajjad kalantari
  • 723
  • 8
  • 23
  • Now it gives me different type of error: The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. Its longer but character limit stops me. –  May 06 '20 at 17:09
  • 1
    see if this link helps you [link](https://stackoverflow.com/questions/37528405/entity-framework-the-context-is-being-used-in-code-first-mode-with-code-that-wa) – sajjad kalantari May 06 '20 at 17:21
  • It's already using it's own generated connection string (so there shouldn't be any errors), but i will try to do some things with it. I will report results. –  May 06 '20 at 19:53
  • connection string has been properly set automatically. Error still persists. –  May 07 '20 at 09:55