Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 无法在本地使用c#代码连接Oracle11g_.net_Oracle - Fatal编程技术网

.net 无法在本地使用c#代码连接Oracle11g

.net 无法在本地使用c#代码连接Oracle11g,.net,oracle,.net,Oracle,我在Windows 2016 server中安装了Oracle11g enterprise。 IP地址是:192.168.2.112 using System; using Oracle.ManagedDataAccess.Client; using Oracle.ManagedDataAccess.Types; namespace OracleTest { class Program { static void Main(string[] args)

我在Windows 2016 server中安装了Oracle11g enterprise。 IP地址是:192.168.2.112

using System;
 using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
namespace OracleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            OracleConnection con = new OracleConnection();
            con.ConnectionString = "Data Source=192.168.2.112:1521/ORCL;User Id=system;Password=Password1;";
            con.Open();
        }
    }
}
我在Oracle服务器上运行代码。它遇到以下错误。

如果我将IP“192.168.2.112”替换为“127.0.0.1”或“localhost”。 它起作用了。 c:\windows\system32\drivers\hosts文件为空。没有自定义条目

Listner.ora文件:

 SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = CLRExtProc)
          (ORACLE_HOME = C:\app\Administrator\product\11.2.0\dbhome_1)
          (PROGRAM = extproc)
          (ENVS = "EXTPROC_DLLS=ONLY:C:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
        )
      )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = C:\app\Administrator

如果这种情况总是发生,那么它实际上意味着机器存在,但它没有在指定端口上侦听的服务,或者有防火墙阻止您

只需尝试使用windows命令远程登录到端口192.168.2.112:1521,并确保端口正在侦听


telnet 192.168.2.112:1521

本地主机
更改为
listener.ora中的ip地址
192.168.2.112
,然后重新启动服务
OracleOraDb11g\u Home1Translistener

 SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = CLRExtProc)
          (ORACLE_HOME = C:\app\Administrator\product\11.2.0\dbhome_1)
          (PROGRAM = extproc)
          (ENVS = "EXTPROC_DLLS=ONLY:C:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
        )
      )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.112)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = C:\app\Administrator
对于诊断,请运行
lsnrctl
实用程序,并查看地址是否列在 侦听端点摘要部分

Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xxx.yyy.zzz)(PORT=1521)))

D:\>lsnrctl

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 05-DEC-2019 08:19:48

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
Start Date                05-NOV-2019 07:19:36
Uptime                    30 days 1 hr. 0 min. 17 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   D:\app\oradba\product\11.2.0\dbhome_1\network\admin\listener.ora
Listener Log File         d:\app\oradba\diag\tnslsnr\xxx.yyy.zzz\listener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xxx.yyy.zzz)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
  Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "r88.rrr.zzz.ddd" has 1 instance(s).
  Instance "r88", status READY, has 1 handler(s) for this service...
Service "r88XDB.rrr.zzz.ddd" has 1 instance(s).
  Instance "r88", status READY, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL>

请不要粘贴图像。以格式化文本的形式提供代码和错误消息(在cmd控制台提示ENTER将所选文本复制到剪贴板)netstat-aon | findstr 1521显示只有127.0.0.1打开了端口。谢谢,将IP条目添加到“listener.ora”文件解决了此问题。我在一些服务中随机遇到了这个问题。看起来如果机器上的IP地址是固定的,我甚至不需要修改listener.ora。但是,如果IP地址是由DHCP动态分配的,我需要添加条目。。。