Thursday, May 30, 2013 MVC 4 website using SQL Server Express instead of SQL Compact Edition

I was working on a sample MVC 4 application and on first run it used SQL Server Express by default for the database. Later I created seed data and set my config file to use SQL Server Compact Edition instead of SQL Server Express. I deleted .mdf from the APP_DATA folder and tried everything I could but application was still using the same old data instead of seed data.
My initializer code:
public class DBInitializer: DropCreateDatabaseIfModelChanges<xxxx>
Here is the small trick I used to fix this issue.

Update the seed data initializer to:
public class DBInitializer: DropCreateDatabaseAlways
and run the application, now your previous data base gets drop and new database using the new configuration will load up. Though its a work around but it fixed the issue. Once you got your new database working you can update the initializer to DropCreateDatabaseIfModelChanges in order to avoid creating database every single time. 

No comments:

Post a Comment