c# - Cannot attach to .mdf file after changing physical directory of solution -


I am following an MVC4 tutorial on Pluralsight, and all my demo projects are controlled through Visual Studio Online I currently only test locally (blue or nothing posted) I am developing an ASP.NET MVC 4 application which uses EF5 code first model. I enabled the migration, and the lower class was created for which I introduced the seed method and automatic migration turned on

  internal seal class configuration. DbMigrationsConfiguration & LT; MyProject.Models.MyProjectContext & gt; {Public Configuration () {AutomaticMgrrans Enabled = True; } Protected Override Zero Seeds (MyProject.Models.MyProjectContext Reference) {context.MyCollection.AddOrUpdate (v = & gt; v.attr1, New MyProject) {ATTR1 = "MVC4", ATTR2 = 120}, New MyProject () { ATTR1 = "LINQ", attr2 = 200}); Context.SaveChanges (); }}  

I'm using the default connection string for my localDb example (not the hard-code path) with the dynamic data directory.

  "AttachDBFilename = | Data Directory | MyProject.Models.MyProjectContext.mdf"  

Until I decided to change the physical directory of my solution By then everything was working as expected. I used the default C: / User / Documents / Visual Studio 2013 / Projects folder from D: / Visual Studio to any other storage drive from the directory Has changed. I updated the mapping of my source control and pulled the project to the new location.

However, when I run my project, I no longer have data. In fact, I can not run the update-database command without receiving the following error message: < / P>

The file 'can not attach to D: \ Visual Studio \ MyProject \ MyProject \ App_Data \ MyProject.Models.MyProjectContext.mdf' MyProject.Models.MyProjectContext 'as database.

I try to stay indefinitely, try to stop running the "enabled-migration" command again, and to store the .mdf file Tried to string-coded the path, but it can never "attach" the database. I know that the database is no longer, but if I run the update-database -force command, if the system does not find the database, it will make a new one

What can I do to retrieve my .mdf file in the App_Data folder?

Maintaining existing data is a non-issue, I should have a new database to continue working for tutorials.

There are several options you can do and you should be able to run the app again.

Option 1

Rename your database name in the web.config file, then run update-database again .

Option 2

Remove the following line from the web.config file, then run Update-Database again.

Attach debufffilename = | Data directory Datacontext.mdf

Option 3

Because you have enabled migration, delete the database from the server explorer, and the Object Explorer and .mdf app_data folder in your app


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -