Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The database cannot be opened because it is version 851. This server supports version 782 and earlier. A downgrade path is not supported

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.

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.

enter image description here

and here is the default SQL Server instance is set in Visual Studio.

enter image description here

like image 220
Musakkhir Sayyed Avatar asked Apr 30 '16 06:04

Musakkhir Sayyed


People also ask

How do you fix the database Cannot be opened because it is version 782?

Try changing Tools > Options > Database Tools > Data Connections > SQL Server Instance Name . The default for VS2013 is (LocalDB)\v11. 0 . Changing to (LocalDB)\MSSQLLocalDB , for example, seems to work - no more version 782 error.


1 Answers

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

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

  • 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

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

like image 127
marc_s Avatar answered Oct 25 '22 14:10

marc_s