I have SchoolContext class that extends DbContext and the connection string in Web.Config
public class SchoolContext : DbContext
{ //This class enables CRUD (Create, Read, Update, Delete) functionality
public DbSet<Student> Students { get; set; }
public DbSet<Course> Courses { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
}
<add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\School.mdf;Initial Catalog=aspnet-WebApplication-20140718100719;Integrated Security=True"
providerName="System.Data.SqlClient" />
The database was initially created. I deleted it to check some initializing stuff. But the database is not been created again, it returns an error saying:
System.Data.SqlClient.SqlException: Cannot attach the file 'c:\Projects\WebApplication\App_Data\School.mdf' as database 'aspnet-WebApplication-20140718100719'.
App_data folder is empty (since I deleted the database). Maybe there are some remaining links/references I need to remove from the projet?
What am I missing?
How can I re-create a Code First Database once it has been deleted?
Thanks
%USERPROFILE%and delete any SQL related file in the top level of that directory, then try again. - Mathias Lykkegaard Lorenzen