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

时间:2019-02-22 00:40:29

标签: sql-server ubuntu windows-subsystem-for-linux

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

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

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

这一直失败。如何格式化/配置它以允许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..

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

TheTFo为我提供的解决方案没有完全起作用。我必须确保还启用了适当的IP地址,从而使它更进一步。有关如何操作的说明,请参见Step 6 of this resource