0

Error number 1

I am getting the above error when trying to add a local Db file to a project in VS2017. The same thing happens if I try to Add > Add new item> SQL server database to the App_data folder.

Install details:

SQL express 2014
C:\Program Files\Microsoft SQL Server\
Named: instance: SQLExpress
instance ID: SQLEXPRESS

This is what I am doing:

Tools> Connect to Database> SQL Server> If I use (LocalDB)\MSSQLLocalDB as "server name:" I get error number 1

If I change the server name and choose the PC name from the drop down I get Error number 2.

Error number 2

I have removed all instances of SQL server and reinstalled, done a repair install on VS2017 still no luck.

I can connect to the server in SQL server object explorer: using PCname\SQLEXPRESS and I can add databases etc, but unable to link to databased under data connections to use with my projects.

SANM2009
  • 1,918
  • 2
  • 12
  • 30
  • That error message is giving you the answer. *"A database with the same name exists..."*. The SQL you're trying to run is trying to create the database `Test` on a server that already has a database called `Test` (or at least has a file called `Test.mdf` in the Data folder). – Thom A Jan 04 '18 at 11:58
  • But I am getting same error if I try to add a new dB. – SANM2009 Jan 04 '18 at 12:00
  • The same error? If you're getting the same error, then that database, or data file also already exists. – Thom A Jan 04 '18 at 12:16
  • They don't exist. – SANM2009 Jan 04 '18 at 12:26

1 Answers1

0

You can connect to a LocalDB instance using named pipes.

1) Get the address of a (localdb) instance by running the following command:

"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe" info [InstanceName]

If the default instance you're interested in, specify v11.0 as the [InstanceName] You can write it in CMD to text file with the command:

"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe" info v11.0 > C:\db_details.txt

2) Copy the "Instance pipe name" value, e.g. np:\.\pipe\LOCALDB#1E0FF40B\tsql\query

3) Paste the "Instance pipe name" value as the Server Name.

Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • This maybe the issue. There is no "SqlLocalDB.exe" in C:\Program Files\Microsoft SQL Server\110\Tools\Binn folder. How do I add it? – SANM2009 Jan 04 '18 at 12:25
  • Check C:\Program Files\Microsoft SQL Server\ - 120, 130, ... it depends on SQL Server version installed on your machine. Or just search for "SqlLocalDB.exe" in C:\Program Files\Microsoft SQL Server\ directory – Dmitry Pavlov Jan 04 '18 at 12:34
  • Do you know what the default instance name for server 2014? – SANM2009 Jan 05 '18 at 08:18
  • Hi, there was no instance to start with, so I created one using create 12.0. But the pipe name is blank for it. How do I give it a pipe name? – SANM2009 Jan 05 '18 at 08:55
  • Make sure you have enabled named pipes and TCP/IP connections https://www.blackbaud.com/files/support/infinityinstaller/content/installermaster/tkenablenamedpipesandtcpipconnections.htm – Dmitry Pavlov Jan 05 '18 at 16:19
  • 1
    I think I have found the route cause of the original issue. For some reason the local dB instance is stopped. When I try to start it, I get an error. So will into sorting that out on Monday now. – SANM2009 Jan 05 '18 at 18:51
  • Still no luck. I have managed to get localdb instances to start but still can't connect to local databases. Sort of given up for now and doing development on another pc which is working fine. – SANM2009 Jan 11 '18 at 09:29
  • @SANM2009 Can you connect to DB from SQL Server Management Studio using the proposed approach? – Dmitry Pavlov Jan 11 '18 at 10:51
  • I don't have SQL Server Management Studio installed, There is no sql server installed, just the sql localdb – SANM2009 Jan 11 '18 at 11:00
  • SQL Server Management Studio is a UI tool to connect to DB (doesn't matter - the local server, local DB, or remote). It is not a SQL server. https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms – Dmitry Pavlov Jan 11 '18 at 11:02
  • Hi, I am having the similar issue on a server can you please help if you can? connection works from app and SSMS when using named pipe. But only works from SSMS when using localdb in con string. https://stackoverflow.com/questions/48296587/cant-connect-to-localdb-but-can-using-namedpipe – SANM2009 Jan 17 '18 at 09:08