Cannot connect to LocalDB via sqlcmd

SQLnewbie picture SQLnewbie · Jul 24, 2016 · Viewed 13.5k times · Source

I am currently learning SQL Server and am having problems connecting to my local database using sqlcmd.

When I type in the following into Powershell:

sqlcmd -S "(localdb)\mssqllocaldb"

I get the following error message:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : SQL Server Network Interfaces: The system cannot find the file specified.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.

I can connect to the local database if I use SQL Server Management Studio. I can also connect to the local database if I use the instance name pipe.

I have a clean install of Windows 10 x64, Visual Studio Community, and SQL Server Management Studio 2016.

Answer

Carrie Kendall picture Carrie Kendall · Jun 19, 2017

There was a driver bug in ODBC Drive 13. Installing ODBC Driver 13.1 update will fix this.

You can download the driver here.

Afterwards, you should be able to use in cmd or powershell:

sqlcmd -S "(localdb)\MSSQLLocalDB" -i C:\path\to\file.sql