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 (the title of this thread). The code where I get the error is shown below (ASP.NET MVC 4):
OdeToFoodDB db = new OdeToFoodDB(); public ActionResult Index() { var model = db.Restaurants.ToList(); return View(model); }
My connection string is the following:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=OdeToFoodDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\OdeToFoodDb.mdf" providerName="System.Data.SqlClient" />
I've tried looking at the SQL Server Object Explorer but it looks the following:
Also, in Server Explorer I don't see any data connections.
And when I try to add a new connection in Server Explorer I don't see any databases named OdeToFoodDb
.
Sorry for this wide question but I'm new to Entity Framework and don't quite get what's wrong here.
A file with . mdf extension is a Master Database File used by Microsoft SQL Server to store user data. It is of prime importance as all the data is stored in this file. The MDF file stores users data in relational databases in the form columns, rows, fields, indexes, views, and tables.
In the 'Object Explorer' window, right-click on the 'Databases' folder and select 'Attach...' The 'Attach Databases' window will open; inside that window click 'Add...' and then navigate to your . MDF file and click 'OK'. Click 'OK' once more to finish attaching the database and you are done.
Launch SSMS -> Connect to the SQL Server instance -> Right-click on Database -> Click Attach. In the new Locate Database Files window, browse the file system to locate the MDF file. Double-click it. The associated data files and log files are populated in the associated files grid view in the Attach Databases window.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With