Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to LocalDB via sqlcmd

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.

like image 661
SQLnewbie Avatar asked Jul 24 '16 07:07

SQLnewbie


1 Answers

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
like image 118
Carrie Kendall Avatar answered Sep 20 '22 20:09

Carrie Kendall