繁体   English   中英

如何从 WSL 2 Linux ZF6F87C39FDCF8B3C2FCZF07 应用程序连接到 Windows 10 上的 SQL 服务器

[英]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 的网络功能相比,可能不需要直接执行此操作。

参考官方文档

如果要获取Windows机器的IP地址,请执行以下步骤:

  1. 您需要检查resolv.conf的内容: cat /etc/resolv.conf
  2. 查看nameserver 它包含所需的 IP 地址。

运行命令示例

我建议您参考此页面以简要了解解析名称服务器。

基本上, nameserver包含名称解析器的 IP 地址。 此名称解析器有助于将 IP 地址与域名相关联。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM