[英]How to connect to SQL Server on Windows 10 from WSL 2 Linux C++ application
我尝试了不同的方法。 SQL 服务器连接失败。 一切都不适合我。 我有一台运行 Windows 10、WSL 2 的主机。我的客人是 Ubuntu。
我正在尝试使用sqlcmd
连接到在我的主机上运行的 SQL 服务器,但我不确定要在连接中使用什么 IP?
我已经暴露/启用了主机 Windows SQL 服务器上的 SQL 服务器配置管理器中的所有内容。
我正在尝试使用 sqlcmd 连接到在我的主机上运行的 SQL 服务器,但我不确定要在连接中使用什么 IP?
您可以从/etc/resolv.conf
获取 IP 地址以使用,如此处所述,例如
david@xxxx:~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.21.224.1
您在172.21.224.1
访问 Windows 主机。 But since the Windows host is configured as your nameserver, you should be able to resolve the hostname of your Windows host, and connect using that, or to your Windows host's "real" IP address.
由于您没有通过环回地址访问 SQL 服务器,因此您还必须添加 Windows 防火墙规则。
但与使用 Docker Desktop 并依赖Docker 的网络功能相比,可能不需要直接执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.