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>

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.

Comments

  1. i too got this error....thank u very much ur solution helped me in fixing it

    ReplyDelete
  2. Thanks for your helping

    ReplyDelete
  3. thanks 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.

    ReplyDelete
  4. Thanks a lot bro...... It will work

    ReplyDelete
  5. A lot new information found until found this topic. Thanks a lot.

    ReplyDelete
  6. very useful, thanks so much!

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

    ReplyDelete
  8. The "DefautlConnection" that comes with the MVC autobuild does not create a db but works with a log file to create the movies.
    This 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"

    ReplyDelete
  9. Thanks Abhi, it's working for me. :)

    ReplyDelete
  10. Thank you man , it works

    ReplyDelete
  11. Thanks Abhimanyu !!! Your suggestion resolved the issue.

    ReplyDelete
  12. Uninstalling Entity Framework 6.0 and Installing Entity Framework 5.0 solved this error.

    In 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

    ReplyDelete

Post a Comment

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System