I have 3 class projects in my solutions. 1. MVC4 project 2. Domain 3. Tests
In the MVC4 project I have added a web.config file with the connection string as
<add name="EfDbContext" connectionString="Data Source=.;Initial Catalog=SportsStore;Integrated Security=true;" providerName="System.Data.SqlClient"/>
I have a class by name EfDbContext in Domain project which inherits DbContext.
When I view the website in browser, I get the server not found error.
I debugged the EfDbContext class and found that the Database.Connection.ConnectionString is set to \SqlExpress with database as EfDbContext.
Why is that?
You must have your connect string as the FULL namespace to your context when your context class is in a different project
For example:
<add name="YourClassProject.EfDbContext" connectionString="Data Source=.;Initial Catalog=SportsStore;Integrated Security=true;" providerName="System.Data.SqlClient"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With