Just in case I am doing something wrong, I have uploaded a video so you can see every step I have done! I am able to reproduce this error.
Video Link
Basically - Start a new MVC 3 project and using EF in the normal way on a simple class.
I used the following connection string:
<add name="databaseconnection" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|database.mdf;User Instance=true;Initial Catalog=database" providerName="System.Data.SqlClient" />
When I navigate to the site, Everything works ok and as expected.
Now, if I try to double click the .mdf database to open it inside of Visual Studio, all hell breaks loose!
I can connect and view the tables as expected, but even if I do nothing and just close (and/or) delete the connection, next time I go to the application, I get the following error:
One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from a backup. Cannot open database "database" requested by the login. The login failed. Login failed for user 'WIL2-8EEA651803\Administrator'. Log file 'c:\documents and settings\administrator\my documents\visual studio 2010\Projects\TestingEF\TestingEF\App_Data\database.ldf' does not match the primary file. It may be from a different database or the lo开发者_运维问答g may have been rebuilt previously.
No matter what I try, I can't reconnect - the only thing I can do is to rename the database and initial catalog. I am sure that the previous version of the MVC Movie Database Tutorial (before they updated to using compact framework) worked fine like this, so I am unsure why I am having these issues.
So, my question is, what is causing this and what should I be doing instead?
Next, Error number 1 in the video, this is a quick XP VM I use for testing, and it happens at random, but did not happen this time and has never happened on the main machine - so I am curious, but not that bothered. When attempting to build the Controller, I get the following error:
"Unable to retrieve metadata for 'TestingEF.Models.blabla'. The provider did not return a ProviderManifestToken string."
Any idea what this is?
I know for the second issue I had to manully drop the database to get this to go away. I think it has to do with the model and the metadata for the model not being in sync int he database.
精彩评论