0

I am developing plug-in for a Windows Forms application. I am trying to use Entity Framework instead of a plain SqlConnection, but it does not work. The application throws the well-known exception:

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

Of course I could add the connection string:

<connectionStrings>
    <add name="testEntities" connectionString="metadata=res://..." />
</connectionStrings>

But I do not have access to the configuration of the application that's running my plugin.

Is there way to use local config in Entity Framework?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Julia
  • 65
  • 9
  • `No connection string named 'testEntity'` and ` – mrogal.ski Jan 11 '17 at 13:45
  • Hi can you please show your DbContext class ? Also are you using EF code first approach ? – Yashveer Singh Jan 11 '17 at 13:45
  • It's really unclear what you mean by "local config". You mean you have Entity Framework in a Class Library, and want the DbContext to use the connectionStrings section from the library's configuration file? – CodeCaster Jan 11 '17 at 13:46
  • 1
    @YashveerSingh how is that relevant? – CodeCaster Jan 11 '17 at 13:46
  • http://stackoverflow.com/questions/31706122/entity-framework-6-connection-string-dll-app-config – CodeCaster Jan 11 '17 at 13:50
  • Ok, I will add DbContext class later. According to "local config" I just cant understand why SQL connection finds connection string but EF does not. So I suggested maybe EF uses another app.config . I comple my plugin to .dll and just drag and drop it to "Plugins" folder of another programm. I dont have access to parent programs source codes – Julia Jan 11 '17 at 13:57

1 Answers1

0

Thanks everyone for responses and providing right direction. I need only get default connection string from application config. So I modified DbContext file according to this answer EntityFramework 6 Code-based configuration of connection string for database-first

Only difference

Properties.Settings.Default.TestConnectionString

Instead manually defined configuration.

Community
  • 1
  • 1
Julia
  • 65
  • 9