sql-serverubuntuwindows-subsystem-for-linux

How do I connect to a local Windows SQL Server Instance from WSL?


I'm new to WSL, and running Ubuntu. I have a local instance of SQL Server 2017 installed in Windows, and want to connect to it from WSL. I have remote connections enabled, however, I can't seem to get connected from ubuntu locally.

I installed the db tools for ubuntu, and I'm using sqlcmd:

sqlcmd -S localhost -U sa -P <my password>

This keeps failing. How do I format/configure this to allow SQL Server in Windows to be available to Ubuntu?

Thanks!

EDIT

I'm using the default instance of SQL Server

Here's the error I'm getting

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 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..

Pinging localhost:

$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=128 time=0.248 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=128 time=0.497 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=128 time=0.517 ms

Solution

    1. Launch SQL Server Configuration Manager
    2. Click on SQL Server Network Configuration
    3. Right click on TCP/IP and click "Enable"
    4. Go to your Services and Restart SQL Server

    Screenshot from Sql Server Configuration Manager