C# .NET - MVC Database not using one in App_Data folder

Asked By Pete Smith on 19-May-12 10:32 AM
Earn up to 10 extra points for answering this tough question.

I have created an mdf database in the app_data folder.

I have added a DB context file and a model that matches the table in the database.

The only connection string is set to reference this database in the app_data folder.

When i run my project it runs fine, will add and delete data ok but the datbase in the app_data folder is not being changed and the table is empty.

it is creting a new sqlserver express database outside of my project and not using the one in the app_data folder.

How do i specify that i want this database to be used rather than creating another one elsewhere

Connection string is:
add name="myDB" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|App_Data|myDB.mdf;User Instance=true" providerName="System.Data.EntityClient"

Context file is:

public class myDBContext : DbContext
{
public DbSet ContentPages { get; set; }
}


Model is

[Table("ContentPages", Schema = "dbo")]
public class ContentPage
{
public int Id {get; set;}

etc. etc.

}

Shan P replied to Pete Smith on 20-May-12 10:04 PM
What happens if you replace App_Data in your connection string with DataDirectory? You can also hardcode the full absolute path as a worst case scenario if that doesn't work. 
Somesh Yadav replied to Pete Smith on 21-May-12 12:19 AM
check this,
http://msdn.microsoft.com/en-us/gg618473
http://stackoverflow.com/questions/7059880/mvc-code-first-app-data-folder-not-being-created