在Visual Studio中安装/连接后连接到SQL Server Express的实体框架错误 [英] Entity Framework error connecting to SQL Server Express after mounting/connecting in Visual Studio

查看:114
本文介绍了在Visual Studio中安装/连接后连接到SQL Server Express的实体框架错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了防万一出错,我已经上传了一个视频,以便您可以看到我所做的每一步!我可以重现这个错误。

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.

视频链接

基本上 - 启动一个新的MVC 3项目,并在一个简单的类中以正常的方式使用EF。

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.

现在,如果我尝试双击.mdf数据库在Visual Studio中打开它,所有的地狱都会松动!

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:


一个或多个文件与数据库的
主文件不匹配。如果
尝试附加数据库,
将使用正确的
文件重试该操作。如果这是一个现有的
数据库,该文件可能已损坏
,并应从备份还原。
无法打开数据库数据库
由登录请求。登录
失败。用户
'WIL2-8EEA651803\Administrator'登录失败。记录
文件'c:\documents和
settings\administrator\my
documents\visual studio
2010 \Projects\TestingEF\TestingEF\App_Data \database.ldf'
与主文件不匹配。
可能来自不同的数据库或
以前日志可能已被重建

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 log may have been rebuilt previously.

无论我尝试什么,我无法重新连接 - 我唯一可以做的是重命名数据库和初始目录。我相信以前版本的MVC电影数据库教程(在更新到使用紧凑框架之前)工作正常,所以我不知道为什么我有这些问题。

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?

接下来,视频中的错误号1,这是一个快速的XP VM用于测试,它随机发生,但这次没有发生,从来没有发生在主机上 - 所以我好奇,但不是那么麻烦。当尝试构建控制器时,我会收到以下错误:

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

任何想法这是什么?

推荐答案

我知道第二个问题我不得不把数据库丢掉,让它消失。我认为它与模型和模型的元数据没有在同步数据库中。

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.

这篇关于在Visual Studio中安装/连接后连接到SQL Server Express的实体框架错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆