0

I am using VS2012 with .NET 4.5. I am learning Entity Framework and I have a problem. I added ADO.NET Entity Data Model to my project and generated my entities using the wizard.

The wizard added a connection string into app.config file :

<add name="MalariaEntities" connectionString="metadata=res://*/MalariaEntities.csdl|res://*/MalariaEntities.ssdl|res://*/MalariaEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=OFIR-PC;initial catalog=Malaria;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

In my project I am seeing all the entities and it seems fine but when I try to do any database action I get the following error:

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

For example, I tried to insert simple row:

using (MalariaEntities DB_Context = new MalariaEntities())
{
    MapsMainCategoriesDsc a = new MapsMainCategoriesDsc();
    a.Category = "aa";
    DB_Context.MapsMainCategoriesDsc.Add(a);
    DB_Context.SaveChanges();
}

When the debugger reach to the last line the exception is raised. What can be the problem?

The wizard added a connection string so why my project cannot use it?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ofir
  • 5,049
  • 5
  • 36
  • 61
  • Do you have separated project for DataAccess or EntityFramework? – spajce Jan 13 '13 at 21:15
  • Yes, my Dal and entity framework sits together in same project but saperatly from my other modules – Ofir Jan 14 '13 at 04:29
  • 1
    okay, in your module from entity framework, just copy and paste the connection string to your main project in app.config. – spajce Jan 14 '13 at 09:45
  • Thanks - it really was my problem – Ofir Jan 14 '13 at 19:34
  • possible duplicate of [Wait! which config file? (Entity Framework Connection String)](http://stackoverflow.com/questions/6223223/wait-which-config-file-entity-framework-connection-string) – Nathan Tuggy Dec 08 '14 at 14:40

0 Answers0