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|.

Lev Dubinets
  • 788
  • 10
  • 32
  • this explains it pretty nicely http://stackoverflow.com/questions/1409358/ado-net-datadirectory-where-is-this-documented – G-Man Apr 10 '13 at 02: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) – Lev Dubinets Apr 11 '13 at 00:01

1 Answers1

1

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

Kiss László
  • 265
  • 4
  • 16