0

I have an application where I am adding a new row in table using EntityFramewok. I wrote a test case which will check the functioning of this addrow method. I am getting count of rows before and after adding the row to DB.
But I am getting an exception when testmethod is trying to access the EF DB.

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

tereško
  • 58,060
  • 25
  • 98
  • 150
Harsha V Chunduri
  • 394
  • 1
  • 4
  • 17

1 Answers1

0

The error is occuring because you have a connection string in Web.Config file of your main project, but your TestProject doesnot know which DB to be referred to.

Solution: Copy the connection string from Web.config of main project (looking similar to the one given below) and paste it into

<connectionStrings> *** </connectionStrings>

of App.config file of TestProject.

<add name="MoviesEntities" connectionString="metadata=res://*/Models.Movies.csdl|res://*/Models.Movies.ssdl|res://*/Models.Movies.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=Movies;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
Harsha V Chunduri
  • 394
  • 1
  • 4
  • 17