I am trying to attach database file in SQL Server. I am getting the below error. The same error I am getting while trying to attach database from Visual Studio. I am using Visual Studio 2013 and SQL Server 2014 Management Studio.
我正在尝试在SQL Server中附加数据库文件。我得到了下面的错误。我在试图从Visual Studio附加数据库时遇到了相同的错误。我使用的是Visual Studio 2013和SQL Server 2014 Management Studio。
My connection string:
我的连接字符串:
<add name="Sample"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\M\Desktop\SampleApplication1\App_Data\Sample.mdf;Initial Catalog=SampleDBContext;Integrated Security=True;"
providerName="System.Data.SqlClient"/>
Error:
错误:
The database 'sample' cannot be opened because it is version 851. This server supports version 782 and earlier. A downgrade path is not supported. Could not open new database 'Sample'. CREATE DATABASE is aborted.
无法打开数据库“sample”,因为它是版本851。此服务器支持版本782和更早的版本。不支持降级路径。无法打开新的数据库“Sample”。创建数据库将中止。
and here is the default SQL Server instance is set in Visual Studio.
这是在Visual Studio中设置的默认SQL Server实例。
2 个解决方案
#1
15
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility. Obviously, your database is from a SQL Server 2016 pre-release (internal version: 852) while the engine you're trying to attach it to is SQL Server 2014 (internal version: 782).
您不能这样做——您不能将一个数据库从一个新的SQL Server版本连接/分离或备份/恢复到一个旧版本——内部文件结构太不一样,无法支持向后兼容性。显然,您的数据库来自一个SQL Server 2016预发布(内部版本:852),而您试图将其附加到的引擎是SQL Server 2014(内部版本:782)。
You can either get around this problem by
你可以绕过这个问题
-
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
在所有机器上使用相同版本的SQL Server——然后在实例之间轻松备份/恢复数据库。
-
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (
Tasks > Generate Scripts
) or using a third-party tool否则,您可以为SQL Server Management Studio (Tasks >生成脚本)或使用第三方工具为结构(表、视图、存储过程等)和内容(表中包含的实际数据)创建数据库脚本
-
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
或者您可以使用像Red-Gate的SQL比较和SQL数据这样的第三方工具,在您的源和目标之间进行“分散”,从这些差异生成更新脚本,然后在目标平台上执行这些脚本;这适用于不同的SQL服务器版本。
#2
0
I was having this issue while following an old Pluralsight MVC4 tutorial.
我在学习Pluralsight MVC4教程时遇到了这个问题。
The course was asking me to use v11.0, but I was running a 2015 version. I opened up the SQL Server Object Explorer and looked at the different versions of LocalDB, and grabbed the name of the one that had my database in it (right-click "Rename").
课程要求我使用v11.0,但我运行的是2015版。我打开SQL Server对象浏览器,查看LocalDB的不同版本,并获取其中包含我的数据库的名称(右键单击“Rename”)。
I then pasted the name in the Add Connection window, under Server Name. Clicked Refresh, and voila, there it was. Hope this helps anyone out there.
然后,我将该名称粘贴到“添加连接”窗口的“服务器名称”下。点击刷新,瞧,就是这样。希望这能帮助任何人。
#1
15
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility. Obviously, your database is from a SQL Server 2016 pre-release (internal version: 852) while the engine you're trying to attach it to is SQL Server 2014 (internal version: 782).
您不能这样做——您不能将一个数据库从一个新的SQL Server版本连接/分离或备份/恢复到一个旧版本——内部文件结构太不一样,无法支持向后兼容性。显然,您的数据库来自一个SQL Server 2016预发布(内部版本:852),而您试图将其附加到的引擎是SQL Server 2014(内部版本:782)。
You can either get around this problem by
你可以绕过这个问题
-
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
在所有机器上使用相同版本的SQL Server——然后在实例之间轻松备份/恢复数据库。
-
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (
Tasks > Generate Scripts
) or using a third-party tool否则,您可以为SQL Server Management Studio (Tasks >生成脚本)或使用第三方工具为结构(表、视图、存储过程等)和内容(表中包含的实际数据)创建数据库脚本
-
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
或者您可以使用像Red-Gate的SQL比较和SQL数据这样的第三方工具,在您的源和目标之间进行“分散”,从这些差异生成更新脚本,然后在目标平台上执行这些脚本;这适用于不同的SQL服务器版本。
#2
0
I was having this issue while following an old Pluralsight MVC4 tutorial.
我在学习Pluralsight MVC4教程时遇到了这个问题。
The course was asking me to use v11.0, but I was running a 2015 version. I opened up the SQL Server Object Explorer and looked at the different versions of LocalDB, and grabbed the name of the one that had my database in it (right-click "Rename").
课程要求我使用v11.0,但我运行的是2015版。我打开SQL Server对象浏览器,查看LocalDB的不同版本,并获取其中包含我的数据库的名称(右键单击“Rename”)。
I then pasted the name in the Add Connection window, under Server Name. Clicked Refresh, and voila, there it was. Hope this helps anyone out there.
然后,我将该名称粘贴到“添加连接”窗口的“服务器名称”下。点击刷新,瞧,就是这样。希望这能帮助任何人。