Building Apps with ASP.NET MVC 4 - Module 4 - Working With Data Pt1

So I completely screwed up my project, MyBeerBlog, because I was having a problem with my login failing on my database. I went in and of course made it much worse to where the project wouldn't work, EF migrations failed, it just turned out to be a total disaster. Luckily, I rolled back to an old commit from before I created the database and I'm going to try it again. Ya, EF migrations are great when you are developing, especially Code First, I'm not fully convinced they are safe for production projects and mature databases. Here's hoping I can get it to work! 


So, I figured out what the problem was, turns out, I didn't really do anything wrong or screw it up very much. I just had my connection string in the web.config file screwed up. I'm following a video that uses Visual Studio 2012 Express and I am using Visual Studio 2015 full edition. What happened was, the video said the Entity Framework would create a local mdf database and that has changed in VS 2015. If you have a copy of SQL Server Express or Full Edition on your server, EF detects that and creates the database there. So, I changed my connection string as follows:

    <add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;
Initial Catalog=MyBeerBlog.Models.MyBeerBlogDb;Integrated Security=True" 
providerName="System.Data.SqlClient" />

There is a good article in MSDN that lists out all the examples of connection strings for various scenarios here.

So now it all works and EF is querying my database just fine. Phew! I thought I was a goner. 

Add comment