在 Visual Studio 中安装/连接后,实体框架连接到 SQL Server Express 时出错
以防万一我做错了什么,我上传了一个视频,这样你就可以看到我所做的每一步!我能够重现这个错误。
基本上 - 启动一个新的 MVC 3 项目并在简单的课程。
我使用了以下连接字符串:
<add name="databaseconnection" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|database.mdf;User Instance=true;Initial Catalog=database" providerName="System.Data.SqlClient" />
当我导航到该站点时,一切工作正常且符合预期。
现在,如果我尝试双击 .mdf 数据库以在 Visual Studio 中打开它,一切都会崩溃!
我可以按预期连接并查看表,但即使我什么都不做,只是关闭(和/或)删除连接,下次访问应用程序时,我会收到以下错误:
一个或多个文件与 数据库的主文件。如果你 正在尝试附加数据库, 使用正确的值重试该操作 文件。如果这是一个现有的 数据库,文件可能已损坏 并且应该从备份中恢复。 无法打开数据库“数据库” 由登录请求。登录 失败的。用户登录失败 'WIL2-8EEA651803\管理员'。日志 文件 'c:\documents 和 设置\管理员\我的 文件\视觉工作室 2010\项目\TestingEF\TestingEF\App_Data\database.ldf' 与主文件不匹配。它 可能来自不同的数据库或 日志可能已被重建 以前。
无论我尝试什么,我都无法重新连接 - 我唯一能做的就是重命名数据库和初始目录。我确信 MVC 电影数据库教程的先前版本(在更新为使用紧凑框架之前)像这样工作得很好,所以我不确定为什么会遇到这些问题。
所以,我的问题是,是什么导致了这种情况,我应该做什么?
接下来,视频中的错误号 1,这是我用于测试的快速 XP 虚拟机,它是随机发生的,但这次没有发生,也从未在主机上发生过 - 所以我很好奇,但并不那么担心。当尝试构建控制器时,我收到以下错误:
"Unable to retrieve metadata for 'TestingEF.Models.blabla'. The provider did not return a ProviderManifestToken string."
知道这是什么吗?
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.
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 log 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道对于第二个问题,我必须手动删除数据库才能解决此问题。我认为这与模型和模型的元数据在数据库中不同步有关。
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.