The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid
It was 2 o'clock at night when I was creating a model (MVC) using Entity Framework. I thought of creating a UnitTest project to follow some TDD. When I tried to run my first TestMethod I got this vague exception. After investigating further with half closed eyes I found out, how dumb I was to not to include App.config in the test project.
Basic concept is pretty straight forward and logical. We generally add entity framework to a class library project in order to be able to reuse the library. The library project is not an executable in its own. Thus we need to add this project in some executable say a console App, windows App, ASP.NET or UnitTest. The runtime will then expect the executable to have a config associated with itself which will have the connection string, which entity framework library is looking for.
Thus, the solution is pretty simple. Add the app.config to the project you are trying to run or add connection string to the config if the project you are trying to run already have a config.
Also - It has been observed that in few cases " present in the connection string can cause similar problem. Try changing it to a single quote (').
Basic concept is pretty straight forward and logical. We generally add entity framework to a class library project in order to be able to reuse the library. The library project is not an executable in its own. Thus we need to add this project in some executable say a console App, windows App, ASP.NET or UnitTest. The runtime will then expect the executable to have a config associated with itself which will have the connection string, which entity framework library is looking for.
Thus, the solution is pretty simple. Add the app.config to the project you are trying to run or add connection string to the config if the project you are trying to run already have a config.
Also - It has been observed that in few cases " present in the connection string can cause similar problem. Try changing it to a single quote (').
Comments
Post a Comment