On my development PC (Windows 10) I have SQL Server Express 2016, including LocalDB installed.
My Windows Form application is using System.Data.SqlClient to connect to a .MDF database. When the .MDF database is version 12 (Sql Server 2014), the connection can be made. However if it is version 13 (Sql Server 2016), then I get an error saying the server instance is version 12, and it can't open.
The connect string is:
"Data Source=(LocalDB)\\MSSQLLocalDB; AttachDbFilename = " + startup_dir +
"\\TAS_Dbase\\Archers1.mdf; Integrated Security = True";
I believe MSSQLLocalDB is the "default" instance of SQL Server, and apparently is version 12 (SQL Server 2014). I need to use the default instance, but want version 13.
Question: How do I change MSSQLLocalDB to version 13?
I have read on a different thread to do the following -
cd "C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn"
SqlLocalDB.exe delete "MSSQLLocalDB"
SqlLocalDB.exe create "MSSQLLocalDB"
I didn't want to do that without checking with someone here first.
Update 6/29 -- I tried using SqlLocalDB command line utility as shown above, but got only the errors shown.
cd "C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn"
SqlLocalDB.exe delete "MSSQLLocalDB"
FormatMessageW failed. Error code returned: 15100
cd "C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn"
SqlLocalDB.exe create "MSSQLLocalDB"
FormatMessageW failed. Error code returned: 15100
How do I fix this?
The best option is to download and install localdb 2017 (version 13) from Microsoft and install it on your system. Multiple localdb versions are allowed to coexist and can be run simultaneously.
No need to make changes to your default mssqllocaldb
.
After installation, Just create the new localdb instance name of your choice by running the following PowerShell command. For example, if you are creating myinstance
instance name:
sqllocaldb.exe "myinstance" 13.0 -s
In your code, replace mssqllocaldb
with your instance name in the connection string:
"Data Source=(LocalDB)\myinstance; AttachDbFilename = " + startup_dir + "\TAS_Dbase\Archers1.mdf; Integrated Security = True";
I solved my problem this way when my database updated to a higher version without my knowledge, while working on a VB.NET project in Visual Studio 2019.