简体   繁体   中英

SQL Server 2016 LocalDb connection issue

I created an application with a .mdf database file (version 13.00.4001).

If I run application on the same computer where I have compiled it, everything works great. But if I try to run it on a second computer with SQL Server LocalDb 2016 installed, it doesn't work and says that SQL Server cannot be found on computer.

What's the problem? I can't understand why.

And if I try to run application on a PC where there is installed SQL Server 2014 LocalDB and 2016 the log says

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

Really I can't understand why there are all these problems.

Code used to build connection string:

"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + 
Directory.GetCurrentDirectory() + 
@"\Dati.mdf; Integrated Security=True"

I Solved my problem by deleting existing MSSQLLocalDB instance and re-create it with this command line

sqllocaldb delete MSSQLLocalDB

and

sqllocaldb create MSSQLLocalDB

and now all works great.

It sounds like you're trying to move your code from one machine to another, but you aren't moving your database. This means you'll need to create a new database on the second machine and then get the new connection string, which will work on the second machine.

Look here for guidance on creating a database, but first install SQL Server Management Studio (look here ). You'll probably want to create some sort of configuration file to put the new connection string in. Here is guidance on that topic.

Version 13.00.4001 corresponds to SQL Server 2016 Service Pack 1 . When you are trying to restore / attach your database on another computer, make sure that not only the same version but also the same SP / CU is installed there.

To verify the version, you can connect to the instance and issue:

print @@version;

It will give you all the necessary information about build, edition, SP / CU, bitness, etc. of the instance in question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM