Unable to retrieve metadata for 'MusicStore.Models.Album'. Using the same DbCompiledModel to create context against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.
You
will get this error in the step by step tutorial (on page here) provided by Microsoft
that starts from here.
If
you look in your solution you will find 'SQL Server CE' database is being used
and to which the application was somehow unable to connect and thus this
message comes up.
Once
you update the connectionString to use a regular 'SQL Server' database will fix
this titled issue.
How to fix?
In
Part 4 of this step by step turorial, you probably have added following code in
you connectionString:
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
</configuration>
<add name="MusicStoreEntities"
connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
</configuration>
Now,
delete above chunk of codes and run the application and try to navigate to ‘Store’
controller, this will automatically create the new and regular ‘SQL Server’ Database
for your project and will also seed some dummy data from a file
‘SampleData.cs’, you will find this in ‘Model’ folder.
And
now, you are ready to go further in that step by step tutorial.
I
hope this fix will help you. Thanks.
i too got this error....thank u very much ur solution helped me in fixing it
ReplyDeleteThanks for your post
ReplyDeleteThanks for your helping
ReplyDeletethanks alot...but one thing that i have noticed is you will need that code which have been deleted after the database has been added. so i think you should better keep it safe and put it later in config file again.
ReplyDeleteThat worked. Thank you sir!
ReplyDeleteThanks a lot bro...... It will work
ReplyDeleteA lot new information found until found this topic. Thanks a lot.
ReplyDeletevery useful, thanks so much!
ReplyDeleteIt worked. Thank for sharing.
ReplyDeleteThanks
ReplyDeleteit helped me..thanku
ReplyDeleteYES..Absolutely do not change ANYTHING, at all, in anyway in the web.config files contents and everything works great..must of course add the new controller's name to the http:\\localxxx\newcontrollersname call.
ReplyDeleteThe "DefautlConnection" that comes with the MVC autobuild does not create a db but works with a log file to create the movies.
ReplyDeleteThis code worked for me creating .mdf and .ldf files in the App_Data folder under the project files.….now will that translate to SQL on hosting web???
<add name="MovieDBContext"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MVCSqlTest;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MVCSqlTest.mdf"
providerName="System.Data.SqlClient"
Thanks Abhi, it's working for me. :)
ReplyDeleteThank you man , it works
ReplyDeleteWorks!
ReplyDeleteThanks Abhimanyu !!! Your suggestion resolved the issue.
ReplyDeleteIt works.. thanks...
ReplyDeleteUninstalling Entity Framework 6.0 and Installing Entity Framework 5.0 solved this error.
ReplyDeleteIn NuGet Package Manager Console I ran below command to solve this issue.
Uninstall Entity Framework 6.0 using below command:
UnInstall-Package EntityFramework.SqlServerCompact UnInstall-Package EntityFramework
Then install Entity Framework 5.0 using below :
Install-Package EntityFramework -Version 5.0.0
Install-Package EntityFramework.SqlServerCompact -Version 4.3.6