Problem So, if you have been doing development with Visual Studio 2010, Entity Framework CodeFirst, SqlServer or SqlServerCE for any amount of time, you’ll quickly run into the problem that the database can not be reinitialized because it is open. Basically, the scenario is this. 1) Put in your Global.asax.cs file a line that always recreates the database (naturally because you are in a development mode and as you constantly change your model and seed data). The line is something like this: Database.SetInitializer(new DropCreateDatabaseAlways<SiteDB>()); 2) Run your application with something like Debug/Run (All is fine) 3) Go into the database browser (either in Visual Studio or Enterprise … Continue Reading
When Using EF CodeFirst With Visual Studio, How to Live With Cannot drop database because it is in use error.
I’ve been struggling with getting the EF CodeFirst right so that it automatically generates foreign keys when the tables are created. I had noticed that there is interesting syntax you can put in to create these foreign keys, however it seemed that the relationships are known so CodeFirst should do that for you. I won’t even bother to go through all the mistakes I made, but if you want to see one, you can check out my forum post where I ask for help. I’m currently writing a series of articles on building a Sencha ExtJS application with Microsoft ASP.NET MVC3. I use codefirst and at the moment I’m building a database of US Presidents and linking them to their Party (republican, democrat, etc.). So, the important thing is … Continue Reading
I have heard all the hype about how great Sql Server CE 4.0 and that it is now standard with Visual Studio 2010 SP1. I’ve got a small project (1 table) that I’d like to include in an asp.net website project so I decided to give it a try. For the most part, things have gone smoothly, however I did have a couple hiccups I’d like to mention. One cost me $9 because I was doing this implementation on an airplane and immediately, I had a failed connection with a confusing error that I needed Bing to lookup (more details below). … Continue Reading