【问题标题】:How do I connect to a local Windows SQL Server Instance from WSL?如何从 WSL 连接到本地 Windows SQL Server 实例?
【发布时间】:2019-07-16 00:48:30
【问题描述】:

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

我为 ubuntu 安装了 db 工具,我正在使用 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

【问题讨论】:

  • “一直失败”是什么意思?您收到什么错误消息?
  • 你能从 Ubuntu ping localhost 吗?您的服务器是默认实例还是命名实例?
  • 感谢您的回复,抱歉我漏掉了这些信息。我用错误编辑了我的帖子,以及 ping 结果。我正在使用默认实例

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


【解决方案1】:

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

【讨论】:

  • 查看我的编辑,添加来自 SQL Server 配置管理器的屏幕截图
  • 谢谢,我到了这一部分,但它仍然无法正常工作。我将发布我需要采取的额外步骤以确保它能够正常工作。
  • 救命.. 感谢您的解决方案
【解决方案2】:

TheTFo 为我提供的解决方案并没有完全奏效。我必须更进一步,确保也启用了适当的 IP 地址。有关如何操作的说明,请参阅Step 6 of this resource

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多