如何从 WSL 连接到本地 Windows SQL 服务器实例?

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

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

我为 ubuntu 安装了数据库工具,我正在使用 sqlcmd:

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

这一直在失败。我如何 format/configure 允许 Windows 中的 SQL 服务器可供 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..

正在 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

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

TheTFo for me did not fully work. I had to take it a step further by ensuring that the appropriate IP Address was enabled as well. Refer to Step 6 of this resource 提供的解决方案,用于说明如何操作。