18

I'm trying to access the "localdb\MSSQLLocalDB" server on my computer through PowerShell with the SQLCMD utility. I'm using PowerShell v5, .NET v5.0, and the server name is (localdb)\MSSQLLocalDB when I connect to it in Microsoft SQL Server Management Studio 2014.

PS C:\> sqlcmd -S localdb\MSSQLLocalDB and PS C:\> sqlcmd -S .\localdb\MSSQLLocalDB result in this error:

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].

I queried the server name in Management Studio with SELECT @@ServerName and used that after the -S in the above command and got the same error.

PS C:\> sqlcmd -S localdb gives this error:

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [53]

Other notes: I'm able to connect to the server and work with a database named testdb01 in a C# console app using System.Data.SqlClient with this connection string:

"Data Source=(localdb)\\mssqllocaldb;Initial Catalog=testdb01;Integrated Security=SSPI;"
Solomon Rutzky
70.1k8 gold badges160 silver badges306 bronze badges
asked Dec 24, 2015 at 18:36
0

1 Answer 1

22

The casing of the instance name does not matter.

You need to try:

sqlcmd -S "(localdb)\MSSQLLocalDB" -d testdb01

The "localdb" part needs to be enclosed in parenthesis as that is a special syntax that points to a SQL Server Express LocalDB-specific API that allows for automatic instance start-up upon being referenced in a connection string. The whole instance name needs to be enclosed in double quotes. The command-line shown above works for me, at least outside of PowerShell.

answered Dec 24, 2015 at 18:53
3
  • Including (localdb) in parenthesis looks like it separates it as a command, and it gives the following error: The term 'localdb' is not recognized as the name of a cmdlet, function, script file, or operable program. Commented Dec 24, 2015 at 18:57
  • 1
    @jmk22 Then try putting the entire server name in double-quotes: -S "(localdb)\MSSQLLocalDB". If that doesn't work then we can try escaping the parenthesis. But somehow those parens need to be there. Commented Dec 24, 2015 at 19:30
  • 1
    The quotations did it, thanks! I've edited your answer to reflect this. Commented Dec 24, 2015 at 19:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.