1

When using the Add Controller helper/scaffolder with Entity Framework CRUD integration, I get the following error:

Unable to retrieve metadata for 'MyApp.Models.MyModel'. Cannot attach the file 
'C:\Users\Lev\AppData\Local\Temp\2d7daf19-d47f-df24-ac76-d3df4fg2sa\aspnet-MyApp-
20130409170533.mdf' as database 'aspnet-MyApp-20130409170533.mdf'.

The question is: Why is it looking for the database in my temp files? The database file is located in:

C:\Projects\MyApp\MyApp\App_Data

This is my connection string:

Data Source=(LocalDb)\v11.0;
Initial Catalog=aspnet-MyApp-20130409170533;
Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|\aspnet-MyApp-20130409170533.mdf

And so it seems that the reference to |DataDirectory| is misbehaving. How can I set DataDirectory? If I manually put the correct path into the AttachDBFilename property, then the scaffolding works. But I'd still love to leave it as |DataDirectory|.

2
  • this explains it pretty nicely stackoverflow.com/questions/1409358/… Commented Apr 10, 2013 at 2:02
  • I'm not sure, but I believe that the web.config file gets executed/compiled before any other code. So if I do any of the stuff in that SO answer, it won't affect the web.config connection string (which is what is used when scaffolding controllers) Commented Apr 11, 2013 at 0:01

1 Answer 1

1

Just restart the Visual Studio. This helped at my project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.