Monday, 29 March 2010

The infamous EntityConnection error:

 

Hi Friends and neighbours ,

I encountered the infamous EntityConnection errror, “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid....”
while unit testing one of  the business component for the solution that I am working on. This particular business component uses an Entity object.

if you have used the The ADO.NET Entity Framework  you know that you need to create the entity data model. When the entity data model or EDM is created using Visual Studio, in this case Visual Studio 2008, a file called “app.config” is also created. This file is created on the same level or should we say next to the EDM file.

project_setup


The app.config file contain the details of the database connection. Since my VS solution is broken up on different layers, one project for each layer, the EDM and app.config file were created on the Data Access layer Project hence my unit tests classes, located on the Test project level, were not able to find the connection details.

The solution : I simply made a copy of the app.config  file available to my Test business project.

TestBusiness

Now if you break up your solution into different projects, with each project representing a layer of your application, don’t forget to either, make a copy of the app.cofnig file available to your ASP NET project or alternative modify your web.config file with the connection string properties found in the app.config file.

Until next time,

“Don’t underestimate the power of The Dark Side”

No comments:

Post a Comment