Basically I\'ve followed a tutorial and decided to delete the .mdf
file afterwards.
Now whenever I try to run the application I get the following error
Recreate your database. Do not delete it and your app should continue to work.
If you happen to apply migrations already this may fix it.
Go to your Web.config and update your connection string based on your migration files.
Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-GigHub-201802102244201.mdf;Initial Catalog=aspnet-GigHub-201802102244201;
The datestrings should match the first numbers on your Migrations.
Remove this line from the connection string that should do it ;) "AttachDbFilename=|DataDirectory|whateverurdatabasenameis-xxxxxxxxxx.mdf"
From Package Manager Console run:
sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
Run your project
You already have an old copy of that database installed in Server Explorer. So its a simple naming collision in the Server Object Explorer / SQL server. You likely created the same database Catalog Name already before you decided to move it to the Apps_Data folder. So that Database name already exists and just needs to be deleted.
Just go into Visual Studio > View > SQL Server Object Explorer and delete the old database name and its connection. Retry your app again and it should install the .mdf file in App_Data and create the same exact database again in the Server Explorer.
I think that for SQL Server Local Db you shouldn't use the Initial Catalog
property.
I suggest to use:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\OdeToFoodDb.mdf"
providerName="System.Data.SqlClient" />
I think that local db doesn't support multiple database on the same mdf file so specify an initial catalog is not supported (or not well supported and I have some strange errors).