如何使用服务器资源管理器附加到由Code First创建的MDF文件 [英] How does one Attach to an MDF file created by Code First using Server Explorer

查看:151
本文介绍了如何使用服务器资源管理器附加到由Code First创建的MDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定:
代码第一技术(所有正确完成和验证)。实际上,在应用程序中可以看到从程序中添加的记录。这意味着所有的SaveChanges和后续查询都可以正常工作。

Given: Code First Technique (all properly done and validated). I can actually, in the application see records added from the program. This means all the SaveChanges and subsequent queries are working.

问题:
我想将此数据库公开到另一个程序,但无法获取Server Explorer数据连接附加到它。

Problem: I want to expose this DB to another program but cannot get Server Explorer Data Connections to attach to it...

您尝试了什么?


  1. 在VS2013中,我打开了服务器资源管理器,点击Add Connetion,输入
    (将DataSource更改为SQLClient,而不是
    默认数据库文件设置):(LocalDb)\V11.0然后在选择或输入数据库名称上单击
    。显示的表未显示
    新的数据库表。

  1. In VS2013 I opened the Server Explorer, clicked on Add Connetion and entered this (after changing the DataSource to SQLClient and not the default database file setting) : (LocalDb)\V11.0 and then clicked on "Selected or enter a database name" The tables shown did not show the new database table.

然后,我尝试输入
MYProject.MYDBContent的完全限定名称,但没有起作用。

I then tried to type in the fully qualified name of MYProject.MYDBContent and that didn't work.

然后我切换到附加数据库文件复选框,
找到创建的文件。 (是的)但是当尝试
打开它说它不能打开,因为它是版本782,这个
服务器支持版本706和更早版本。后来,消息说
还具有相同名称的数据库存在,或者指定的文件不能
被打开,或者它位于UNC共享。

I then switched to the checkbox of "Attach a database file" and found the file that was created. (Yes!) But when attempting to open it says It cannot be opened because it is version 782, this server supports version 706 and earlier. Later on, the message says also "A database with the same name exists, or specified file cannot be opened, or it is located on a UNC Share."

环境

我使用VS2013并使用NUGET下载EF 6.0.2,但是当我
看到参考区域中的EF告诉我它仍然是版本
4.0 ....

I'm using VS2013 and used NUGET to download EF 6.0.2, but when I look at EF in the references area is tells me it's still Version 4.0....

我的系统同时安装了SQL Server 2012和2014(本地DB)。这应该是根本原因。

My system has both SQL Server 2012 and 2014 (Local DB) installed. This must be root cause of issue.

想法?

Visual Studio 2013,EF 6.0.1和SQL Express 2012在使用Code First时不能很好地协同工作。问题是生成MDF文件,但是使用服务器资源管理器数据连接进行任何连接尝试都将失败,并出现上述782错误消息以及SQL 2012的SSMS。即使您的系统未安装SQL 2014,MDF文件版本也认为这是一个2014年的文件版本!

Visual Studio 2013, EF 6.0.1 and SQL Express 2012 do not work well together when using Code First. The problem is the MDF file is generated but any attempt to connect using the Server Explorer Data Connections fails with the 782 error message above as well as in SSMS for SQL 2012. Even if your system does not have SQL 2014 installed the MDF file version thinks it is a 2014 file version!

如果你删除一个MDF文件(像我以前一样)尝试创建MDF失败(无法附加文件错误),那么只需重命名DBContext类名,您将获得一个新的MDF文件!

If you delete an MDF file (as I did and subsequent) attempts to create MDF fail (Cannot Attach File error), then simply rename the DBContext class name and you will get a new MDF file!

环境:

推荐答案

Visual Studio 2013在使用Code First时,EF 6.0.1和SQL Express 2012不能很好地协同工作。问题是生成MDF文件,但是使用服务器资源管理器数据连接的任何尝试连接失败,并出现上述782错误消息以及SQL 2012的SSMS。即使您的系统没有安装SQL 2014,MDF文件版本认为这是一个2014文件版本!

Visual Studio 2013, EF 6.0.1 and SQL Express 2012 do not work well together when using Code First. The problem is the MDF file is generated but any attempt to connect using the Server Explorer Data Connections fails with the 782 error message above as well as in SSMS for SQL 2012. Even if your system does not have SQL 2014 installed the MDF file version thinks it is a 2014 file version!

答案:
如果您删除MDF文件我做的)和随后的尝试创建MDF失败(无法附加文件错误),然后只需重命名DBContext类名称,您将获得一个新的MDF文件!

Answer: If you delete an MDF file (as I did) and subsequent attempts to create MDF fail with(Cannot Attach File error), then simply rename the DBContext class name and you will get a new MDF file!

这篇关于如何使用服务器资源管理器附加到由Code First创建的MDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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