1

I have VS 2017, SQL Server 2017 Configuration Manager and SQL Server 2017 management tools.

My connection string is

Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\test.mdf;Integrated Security=True;Connect Timeout=30

The version of connection: 13.00.4001

When I run my app in another PC I installed the SQL Server LocalDB 2017 and my app works perfectly!

But when I copied the .MDF and .LDF files from that PC and tried to added them to new project I got this error:

cannot be opened because it is version 869. This server supports version 852 and earlier. A downgrade path is not supported.

and this:

A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Why VS 2017 does not allow me to use this database?

It seems SQL Server localDB 2017 does NOT JUST support SQL Server 2016, it also modified the .MDF file to become 869 version (SQL Server localDB 2017 as I think because I am able to attach the .MDF in SQL Server 2017 Management Studio).

But the question now :

I already installed SQL Server 2017 Management tools - why do I get this error ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nano
  • 64
  • 1
  • 1
  • 8
  • 2
    The version number is the version of the database file. This is distinct from the version number of SQL Server itself, but later versions of SQL Server use later file versions as well. As soon as you attach a database, it is upgraded to the latest version SQL Server knows, or you get an error because it is later than the latest version it knows. You cannot attach a database that's been used in SQL Server 2017 to a SQL Server 2016 instance, and that's the version used by VS 2017 (which came out before SQL Server 2017 did). – Jeroen Mostert Apr 18 '18 at 12:37
  • 1
    What you need to install is SQL Server 2017, not its management tools. Installing SQL Server 2017 LocalDB will allow you to create a new instance with the proper version. You can delete the existing `MSSqlLocalDB` instance and create it with the newer version using the `sqllocaldb` command-line tool. I don't think you can upgrade it, so you'll have to reattach databases. – Jeroen Mostert Apr 18 '18 at 12:41
  • Possible duplicate of [cannot be opened because it is version 706. This server supports version 662 and earlier. A downgrade path is not supported](https://stackoverflow.com/questions/19890891/cannot-be-opened-because-it-is-version-706-this-server-supports-version-662-and) – Ken White Apr 18 '18 at 12:43
  • Thank you, That was clear. But I already have SQL server express 2017 not just management tools. As i understand from you I need to let VS depend on SQL Server 2017 LocalDB, Yo said "You can delete the existing MSSqlLocalDB instance and create it with the newer version using the sqllocaldb command-line tool" CAn you kindly tell me how to do this ? – Nano Apr 18 '18 at 13:03
  • `sqllocaldb` with no arguments gives pretty clear documentation. Use `sqllocaldb v` to verify you really have 2017, `sqllocaldb d` to delete the existing instance, `sqllocaldb c` to create one. You may run into trouble as you do this because there's a bug in 2016 SP1; [discussion and fix](https://social.msdn.microsoft.com/Forums/en-US/1257bf26-6ab0-416d-bf26-34f128f42248/sql-2016-sp1-sqllocaldb-versions-errors-with-windows-api-call-reggetvaluew-returned-error-code?forum=sqlexpress#1257bf26-6ab0-416d-bf26-34f128f42248). – Jeroen Mostert Apr 18 '18 at 13:12
  • That's work AWESOME! I made the steps using command line as you said. Thank you very much. – Nano Apr 18 '18 at 13:46

0 Answers0