SQL Server Express连接到.mdf文件 [英] SQL Server Express connection to .mdf file

查看:334
本文介绍了SQL Server Express连接到.mdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两部分问题.

我已经使用VS 2015 Update 3创建了一个ASP.NET MVC 5应用程序.与本地计算机上的项目一起使用时,我有很多方法.突然,我无法再通过SQL Server对象资源管理器连接到.mdf数据库文件并得到以下错误:

I have created an ASP.NET MVC 5 application using VS 2015 Update 3. I am quite a ways along with the project on my local machine. Suddenly, I can no longer connect via SQL Server Object Explorer to the .mdf database file and get the following error:

数据库'aspnet-DevilsTowerMVC-20180327093314'无法打开,因为它的版本为852.此服务器支持版本782和更早的版本.不支持降级路径.无法打开新数据库"aspnet-DevilsTowerMVC-20180327093314". CREATE DATABASE被中止.无法将文件'D:\ VS2015 \ DevilsTowerMVC \ App_Data \ aspnet-DevilsTowerMVC-20180327093314.mdf'附加为数据库'aspnet-DevilsTowerMVC-20180327093314'.

The database 'aspnet-DevilsTowerMVC-20180327093314' cannot be opened because it is version 852. This server supports version 782 and earlier. A downgrade path is not supported. Could not open new database 'aspnet-DevilsTowerMVC-20180327093314'. CREATE DATABASE is aborted. Cannot attach the file 'D:\VS2015\DevilsTowerMVC\App_Data\aspnet-DevilsTowerMVC-20180327093314.mdf' as database 'aspnet-DevilsTowerMVC-20180327093314'.

我的计算机上安装了SQL Server 2012(11.0.5388.0).该项目是使用VS 2015创建的.我看到了

I have SQL Server 2012 (11.0.5388.0) installed on my machine. The project was created using VS 2015. I saw a similar question on SO but this did not provide a definitive answer.

我刚刚在VS 2015中创建了另一个ASP.NET MVC 5应用程序,并且登录工作正常(例如SQL Server 12.00.2000).所以我不明白我现有的项目如何神秘地还原为旧版本?

I just created another ASP.NET MVC 5 app in VS 2015 and the login worked perfectly (says SQL Server 12.00.2000). So I don't understand how my existing project mysteriously reverted to an older version?

根据我的研究,SQL Server 2016的内部数据库版本号为852,而SQL Server 2014的内部数据库版本号为782.我安装的SQL Server 2012的内部数据库版本号为706,所以我不知道为什么在错误消息中提到"782".

From my research, SQL Server 2016 has an internal database version number of 852, and SQL Server 2014 and has an internal DB version number of 782. My installation of SQL Server 2012 has an internal DB version number of 706, so I don't know why it's mentioning '782' in the error message.

(Q1)如果我无法降级,那么我唯一的选择可能是安装SQL Server 2016 Express?这是正确的吗?要正确执行什么步骤?如果没有,是否有办法重置"它-新创建的项目就可以了吗?

(Q1) If I cannot downgrade then my only option may be to install SQL Server 2016 Express? Is this correct and what are the steps to do this correctly? If not, is there a way to 'reset' it - newly created project works just fine?

(第2季度)如何将其转换为在SSMS中使用常规的基于非文件的常规SQL Server数据库?

(Q2) How do I convert this to use a regular non-file-based SQL Server database in SSMS?

我的web.config:

My web.config:

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-DevilsTowerMVC-20180327093314.mdf;Initial Catalog=aspnet-DevilsTowerMVC-20180327093314;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="mssqllocaldb"/>
        </parameters>
   </defaultConnectionFactory>
</entityFramework>

更新1

我从此处下载了SQL Server 2016 SP1 Express Edition .我选择了下载媒体/LocalDB"选项.它似乎已正确安装.但是,当我在Server Explorter中选择DefaultConnection并单击刷新"时,会得到与以前完全相同的错误.我尝试了连接字符串中的所有组合,例如:(LocalDb)(LocalDb)\v11.0(LocalDb)\MSSQLLocalDB.

I downloaded the SQL Server 2016 SP1 Express Edition from here. I selected the Download Media/LocalDB option. It appeared to install correctly. However, when I select the DefaultConnection in Server Explorter and hit refresh, I get the exact same error as before. I tried all combinations in my connection string, such as: (LocalDb), (LocalDb)\v11.0 and (LocalDb)\MSSQLLocalDB.

当我查看C:\ Windows \ SysWOW64文件夹时,我看到仍安装了SQLServerManager11.msc配置管理器.

When I look in the C:\Windows\SysWOW64 folder, I see the SQLServerManager11.msc configuration manager still installed.

更新2

我从App_Data文件夹中删除了.mdf文件,并尝试通过注册新用户来重新创建它.创建了DefaultConnection.mdf文件,但是当我尝试在Server Explorer中添加它时,却得到了与以前相同的版本错误消息.任何人都可以提出一种赎回项目登录系统的方法吗?

I deleted the .mdf file from the App_Data folder and tried recreating it by registering a new user. A DefaultConnection.mdf file was created, but when I tried adding it in Server Explorer I got the same version error message as before. Can anyone suggest a way to redeem the project login system?

推荐答案

我借助Yair M对

I managed to solve this problem with the aid of an answer by Yair M to this question.

我首先使用控制面板->程序和工具,以物理方式卸载了与我的SQL Server 2012版本相对应的v11.0之外的所有版本的LocalDb.功能.

I first physically uninstalled all versions of LocalDb aside from the v11.0 one which corresponded to my version of SQL Server 2012, using the Control Panel --> Programs & Features.

然后使用命令行,我发出了以下命令:

Then using the command line, I issued the following commands:

sqllocaldb删除"v11.0"

sqllocaldb delete "v11.0"

sqllocaldb创建"v11.0"

sqllocaldb create "v11.0"

这解决了当我尝试注册新用户时擦拭而不重新创建基于文件的LocalDb实例的问题.

This solved the issue where the file based instance of LocalDb was being wiped and not re-created when I tried to register a new user.

此时,我可以注册一个新用户,而不会出现任何错误消息.但是,我想离开LocalDB.

At this point I could register a new user without any error messages. However, I wanted to move away from LocalDB.

因此,我在SSMS中创建了一个空数据库,并将.mdf文件附加到该数据库.我更新了连接字符串,以使用实际的数据库和集成安全性(用于本地开发).运行该应用程序时出现一些权限错误,但能够通过创建一个新用户并赋予其读写访问权限来解决此问题.

So, I created an empty database in SSMS and attached the .mdf file to it. I updated my connection string to use an actual DB and Integrated Security (for local development). I got some permissions errors when running the app, but was able to remedy this by creating a new user and giving it read and write access.

<add name="DefaultConnection" 
  connectionString="Initial Catalog=DevilsTower;Data Source=Development;Integrated Security=SSPI;" 
    providerName="System.Data.SqlClient" />

这篇关于SQL Server Express连接到.mdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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