Where is that file on my system?
Asked Answered
S

1

1

Am trying to learn ASP.NET MVC and search the internet in and out including SO. A lot of questions and answers about |DataDirectory| as where and how.

When debugging the site breaks:

"The model backing the 'ASPNETDBContext' context has changed since the database was created...".

Then I checked the path: |DataDirectory|ASPNETDBContext.sdf

 string path = AppDomain.CurrentDomain.GetData( "DataDirectory" ).ToString();

It points to the App_Data of the project but no file there.

The DB is entirely empty so deleting the thing is all I need.

My actual question I need to be answered: How to fix this properly?

made a follow-up: And additionally: Where is that file!

Sprite answered 29/8, 2012 at 1:4 Comment(2)
First of all it should be "|DataDirectory|ASPNETDBContext.mdf" (notice the extension difference). Your application is obviously trying to use a database, however that database file is not found. Are you using Entity Framework? Is there an edmx file in your project?Lefthanded
@niaher: Wondered about that too, just going with the flow of Rick Andersen's tutorial: Adding a Model (C#) of which is talking about the .sdf. There is no emdx file and it is EF (Code First).Sprite
J
1

The answer to your problem lies in reading Scott Guthrie's blog

For those who are seeing this exception:

"The model backing the 'Production' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance."

Here is what is going on and what to do about it:

When a model is first created, we run a DatabaseInitializer to do things like create the database if it's not there or add seed data. The default DatabaseInitializer tries to compare the database schema needed to use the model with a hash of the schema stored in an EdmMetadata table that is created with a database (when Code First is the one creating the database). Existing databases won’t have the EdmMetadata table and so won’t have the hash…and the implementation today will throw if that table is missing. We'll work on changing this behavior before we ship the fial version since it is the default. Until then, existing databases do not generally need any database initializer so it can be turned off for your context type by calling:

Database.SetInitializer<Production>(null);

Hope this will help you resolve the issue.

Jorum answered 29/8, 2012 at 4:41 Comment(3)
@All: but still I want to know where that file can be physically found at my hdd. Used the search for it but no luck.Sprite
1. if resolved, please mark as correct answer. 2. on your hard drive, do you know where your project is? by default its under your <user name>/Documents/Visual Studio 2010/Projects/<Project Name>/<Project Name>/App_Data/. But if your config isn't default there's no way somebody will be able to answer that question :)Jorum
1. If resolved means it's fixed, understood and a valid solution you are right. Remember understood. SO isn't a race, it's about correct information. 2. hummm.Sprite

© 2022 - 2024 — McMap. All rights reserved.