Pergunta

I have been struggling with this issue for some time, and I cant find any solution in the web.

I have a solution (.NET 4 C# VS 2010) with three projects (Presentation[Balance], Data[Data], BussinessLogic[Logica]). The idea was to use a tier-3 architecture.

enter image description here

My Database is SQL Compact Edition 3.5 named Balance.sdf. Then, in my Data project, I created an ADO .NET Entity Data Model, so as to use Entity Framework to do the mapping with the database.

The mapping is done correctly and the connection string is added fine in the Data App.Config:

<connectionStrings>
<add name="BalanceEntities" connectionString="metadata=res://*/DatabaseModel.csdl|res://*/DatabaseModel.ssdl|res://*/DatabaseModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=|DataDirectory|\Balance.sdf;Password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />  
</connectionStrings>

Then, Balance(Presentation [WPF]) references Data to use the entities, and Logica to call the methods.

The problem is that when I call any of the static methods from Logica classes that involves using an instance of DatabaseModel.edmx, I get this exception:

ArgumentException was unhandled: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

This occurs in the constructor:

enter image description here

What I tried, was to add the ADO .NET Entity Data Model in the Balance project and it worked perfectly. So I guess it must be something related to the App.Config. Anybody know why this could be happening?

Thanks for reading!

Foi útil?

Solução

Add the same connection string to your Balance project, so this should also be in the App.Config

<connectionStrings>
<add name="BalanceEntities" connectionString="metadata=res://*/DatabaseModel.csdl|res://*/DatabaseModel.ssdl|res://*/DatabaseModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=|DataDirectory|\Balance.sdf;Password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />  
</connectionStrings>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top