You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

主机无法通过SQL Developer/VSCode连接Hyper-V虚拟机上的Oracle 19c

主机无法连接Hyper-V虚拟机上的Oracle 19c数据库

报错信息

SQL Developer报错

执行请求操作时遇到错误:IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=jaboSwmfSBiYukjDv3hEsg==) Vendor code 17002

VSCode报错

Error: A connection with the database could not be established
Source: Oracle SQL Developer Extension for VSCode

环境配置

  • 主机:Windows 11 Pro,已安装VSCode、Oracle client for Microsoft Tools,配置instantclient_19_24环境变量路径
  • Hyper-V虚拟机:Windows Server 2016,与主机共用笔记本内置唯一网络适配器
  • 虚拟机内可正常通过SQL Developer和VSCode连接Oracle 19c

Oracle监听器状态

执行命令:

C:\Users\Administrator>lsnrctl status

输出:

LSNRCTL for 64-bit Windows: Version 19.0.0.0.0 - Production on 19-AUG-2024 13:18:33
Copyright (c) 1991, 2019, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=VMWIN2016SER)(PORT=1521)))
STATUS of the LISTENER

Alias                     LISTENER
Version                   TNSLSNR for 64-bit Windows: Version 19.0.0.0.0 - Production
Start Date                19-AUG-2024 11:35:09
Uptime                    0 days 1 hr. 43 min. 24 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   C:\db_home\network\admin\listener.ora
Listener Log File         C:\oracle19c_agcadmin\diag\tnslsnr\VMWIN2016SER\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=VMWIN2016SER)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=VMWIN2016SER)(PORT=5500))(Security=(my_wallet_directory=C:\ORACLE19C_AGCADMIN\admin\orcl\xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "52448234712340b69f274bcc790ecfe0.agc.local" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "66d05b08751d4f5399f9cf1e3e332e21.agc.local" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl.agc.local" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB.agc.local" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclpdb.agc.local" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

排查与解决步骤

1. 检查Hyper-V虚拟机网络配置

  • 确认虚拟机网络适配器类型为外部网络,绑定到主机物理网卡,保证主机与虚拟机处于同一局域网段
  • 在虚拟机中执行ipconfig,记录虚拟机的IPv4地址(例如192.168.x.x)

2. 修改Oracle监听器配置

  • 打开虚拟机内C:\db_home\network\admin\listener.ora文件
  • 将监听地址的HOST从VMWIN2016SER改为虚拟机IPv4地址,或设置为0.0.0.0(允许所有IP访问),修改后示例:
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.x.x)(PORT = 1521))
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
        )
      )
    
  • 重启监听器:依次执行lsnrctl stop和lsnrctl start命令

3. 测试网络连通性与端口可用性

  • 在主机CMD中执行ping <虚拟机IPv4地址>,确认网络连通
  • 执行telnet <虚拟机IPv4地址> 1521,测试1521端口是否可访问;若不通,需在虚拟机中添加1521端口的入站防火墙规则,或临时关闭防火墙验证

4. 主机端连接配置

  • 在SQL Developer/VSCode的连接配置中,将主机地址设为虚拟机IPv4地址,端口保持1521,服务名使用监听器状态中显示的orcl.agc.local或orclpdb.agc.local
  • 若使用TNS连接,可在主机instantclient_19_24\network\admin目录下创建tnsnames.ora,示例配置:
    ORCL =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.x.x)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = orcl.agc.local)
        )
      )
    

内容的提问来源于stack exchange,提问作者user9803698

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 11:29:54