1

I'm a complete newbie in ASP.NET MVC 4. I'm following this nice tutorial about ASP.NET MVC,

And I'm stuck at one point.

I'm trying to add a new Controller called MoviesController.cs, but Visual Studio 2010 is yielding the error :

Unable to retrieve metadata for 'MvcMovie.Models.Movie'. Invalid value for key 'attachdbfilename'.

I think by attachdbfilename, it is referring to this line in Web.Config file :

<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
 providerName="System.Data.SqlClient" />

I have also searched for this in StackOverFlow, one solution was to install Microsoft SQL Server Compact 4.0, I installed it but nothing changed.

May be related:

I also have WAMPServer installed on my Windows 7 64-bit, but I have stopped all services and closed the application before I did anything.

So how do I solve this issue?

Thanks !

Edit

Now I started to think that |DataDirectory| Should be changed with a path. is it true? if so, which path?

And what is this Movies.mdf file? Is is some kind of .sql file? And should I have already created it at some location?

tereško
  • 58,060
  • 25
  • 98
  • 150
jeff
  • 13,055
  • 29
  • 78
  • 136
  • Duplicate of http://stackoverflow.com/questions/17525905/unable-to-retrieve-metadata-mvc-application/17526947#17526947 – Lotok Jul 16 '13 at 21:27
  • 1
    The MDF file is mentioned about half way down the tutorial at a bit titled `Working with SQL Server LocalDB`. Also there is a cracking set of tutorials from Scott Allen free here which I recommend watching: http://www.asp.net/mvc/videos/pluralsight-building-applications-with-aspnet-mvc-4 – Lotok Jul 16 '13 at 21:29
  • Thanks ! So I need to change it to App_Data? And what if I want it to connect to my WAMPServer Database ? Or even another database like SQLite or remote ? – jeff Jul 16 '13 at 21:35
  • 1
    DataDirectory == App_Data. Different database types just mean a different connection string. – Lotok Jul 16 '13 at 21:52
  • Ok! Thank you so much man. I found the solution btw, I'm posting it now. – jeff Jul 16 '13 at 21:57

2 Answers2

3

If you are using SQL Express, then the connection string needs to be modified. I modified and used the below connection string and it worked for me.

<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Movies;AttachDBFilename=|DataDirectory|\Movies.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
Anu
  • 31
  • 2
0

I found the answer in this topic : http://forums.asp.net/post/5120530.aspx

It worked when I changed the line to this :

<connectionStrings>

<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=Movies;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

  </connectionStrings>

I also installed Sql Server Data Tools, but not sure if it's relevant.

jeff
  • 13,055
  • 29
  • 78
  • 136