如何从 WSL 连接到本地 Windows SQL Server 实例?

The*_*TFo 8 sql-server ubuntu windows-subsystem-for-linux

我是 WSL 的新手,正在运行 Ubuntu。我在 Windows 中安装了 SQL Server 2017 的本地实例,并想从 WSL 连接到它。我启用了远程连接,但是,我似乎无法在本地从 ubuntu 连接。

我为 ubuntu 安装了 db 工具,我正在使用 sqlcmd:

sqlcmd -S localhost -U sa -P <my password>
Run Code Online (Sandbox Code Playgroud)

这一直失败。我如何格式化/配置它以允许 Windows 中的 SQL Server 可用于 Ubuntu?

谢谢!

编辑

我正在使用 SQL Server 的默认实例

这是我得到的错误

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..
Run Code Online (Sandbox Code Playgroud)

ping 本地主机:

$ 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
Run Code Online (Sandbox Code Playgroud)

Mat*_*ler 10

TheTfo为我提供的解决方案并没有完全起作用。我必须更进一步,确保也启用了适当的 IP 地址:

在“协议”选项卡上,确保为“启用”选择“是”,而且在“IP 地址”选项卡上,确保为相应的 IP 地址选择“是”,并检查 TCP 端口是否设置正确(可能为空):

在此输入图像描述

来源


The*_*TFo 7

我想出了我的问题。服务器协议中未启用 TCP/IP。

在此处输入图片说明