I have an existing project with a small handful of data models, and I'm trying to create a SQL Server Express database with Visual Studio 2015 and open that database in SQL Server Management Studio.
I've enabled migrations in Visual Studio, which generated a migration Configuration.cs file that looks like this:
internal sealed class Configuration : DbMigrationsConfiguration<MyDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
ContextKey = "Fully.Qualified.Namespace.MyDbContext";
}
}
I then added a migration, which generated a migration file with the appropriate up and down functions. So far so good.
I want to create the database file in my App_Data directory, so I created a web.config entry that looks like this:
<add name="MyDatabaseName" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabaseName.mdf;Initial Catalog=MyDatabaseName;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
The app runs fine, but when I submit the user registration form, I get this error:
Unable to open the physical file "<path>\App_Data\MyDatabaseName.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
Right. I thought Visual Studio was supposed to create that file for me? I went ahead and created the database file in App_Data, and that gave me this error:
The database 'MyDatabaseName' cannot be opened because it is version 852. This server supports version 706 and earlier. A downgrade path is not supported.
I'm sure there's a way around that versioning error, but why isn't Visual Studio just creating the .mdf file for me?