How to handle "No connection string named 'RestaurentEntities' could be found in the application config file" in WinForms

c# entity-framework entity-framework-6 syncfusion winforms

Question

I hope you all will be fine.

I am trying a project on WinForms. I made a Form name Dashboard and User Control name DashboardScreen. Dashboard basically will have many User Controls on it like DashboardScreen, InventoryScreen, SettingsScreen etc. These screens are small and Dock in main parent form Dashboard so when user click on button, corresponding user control comes to the front using DashboardScreen.BringToFront()

These user controls are implementing Entity Framework V 6.4.0 User controls and Main Dashboard Form works fine when I do not use Entity Framework on these controls. Whenever I use Entity Framework as RestaurentEntities DB = new RestaurentEntities(); to utilize database services the Main Dashboard Form gives the following Error in Design Mode.

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

Second Error is

The variable 'dashboardScreen' is either undeclared or was never assigned.

Given is my configuration 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.5.2" />
  </startup>
  <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>
  <connectionStrings><add name="RestaurentEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=YASIR\SQLDEVENV;initial catalog=Restaurent;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
1
0
12/19/2019 4:05:37 PM

Popular Answer

Change your connectionStrings to below:

<connectionStrings>
    <add name="RestaurentEntities" 
   connectionString="data source=YASIR\SQLDEVENV;initial catalog=Restaurent;integrated 
   security=True;MultipleActiveResultSets=True;App=EntityFramework" 
   providerName="System.Data.SqlClient" />
</connectionStrings>  

And make sure that

your Dbcontext constructor is like

    public RestaurentEntities ()
        : base("name=RestaurentEntities")
    {


    }
0
12/20/2019 7:05:15 PM


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