查看: 137264|回复: 22

[原创] 郁闷的The Network Adapter could not establish the connection

[复制链接]
论坛徽章:
1
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44
跳转到指定楼层
1#
发表于 2007-10-11 22:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
郁闷的The Network Adapter could not establish the connection
各位大虾,最近碰到很奇怪的事,如果访问量大的话,常报The Network Adapter could not establish the connection的错,但同一个程序别的类调用数据库连接却能联上,而且报这种错的类是不一定的,有时这个类报这个错,有时另外一个类报这个错的,我的程序是多线程的,现在很苦恼,查了一两天都没查出来原类,用户那边正在抱怨着呢,领导要求最近一定要查出来,请大家帮忙看看是什么原因,多谢了:
我的数据库驱动程序是classes12.jar ,数据库连接用的是odbcracle:thin:@172.18.26.89:1521racl
驱动为oracle.jdbc.driver.OracleDriver
我换了classes14.jar,驱动racle.jdbc.OracleDriver,也报这个错
我将ora文件的process调成500个,还报这个错
论坛徽章:
9
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:08:29ITPUB9周年纪念徽章
日期:2010-10-08 09:28:522011新春纪念徽章
日期:2011-02-18 11:42:47ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
2#
发表于 2007-10-12 16:12 | 只看该作者

Re: 郁闷的The Network Adapter could not establish the connection

最初由 北极羊 发布
[B]郁闷的The Network Adapter could not establish the connection
各位大虾,最近碰到很奇怪的事,如果访问量大的话,常报The Network Adapter could not establish the connection的错,但同一个程序别的类调用数据库连接却能联上,而且报这种错的类是不一定的,有时这个类报这个错,有时另外一个类报这个错的,我的程序是多线程的,现在很苦恼,查了一两天都没查出来原类,用户那边正在抱怨着呢,领导要求最近一定要查出来,请大家帮忙看看是什么原因,多谢了:
我的数据库驱动程序是classes12.jar ,数据库连接用的是odbcracle:thin:@172.18.26.89:1521racl
驱动为oracle.jdbc.driver.OracleDriver
我换了classes14.jar,驱动racle.jdbc.OracleDriver,也报这个错
我将ora文件的process调成500个,还报这个错 [/B]



偶知道

使用道具 举报

回复
论坛徽章:
9
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:08:29ITPUB9周年纪念徽章
日期:2010-10-08 09:28:522011新春纪念徽章
日期:2011-02-18 11:42:47ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
3#
发表于 2007-10-12 22:06 | 只看该作者
在 hosts中记录你RAC节点的IP就可以了!

使用道具 举报

回复
论坛徽章:
1
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44
4#
 楼主| 发表于 2007-10-12 22:22 | 只看该作者

楼上能说得更清楚点吗

楼上能说得更清楚点吗

使用道具 举报

回复
论坛徽章:
9
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:08:29ITPUB9周年纪念徽章
日期:2010-10-08 09:28:522011新春纪念徽章
日期:2011-02-18 11:42:47ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
5#
发表于 2007-10-13 11:01 | 只看该作者
如果DB是unix/linux系统上,则把 /etc/hosts中的IP记录到客户端(一般是Windows)的C:\WINDOWS\system32\drivers\etc\hosts文件中,如果你没有使用DNS的话
如果DB是在Windows上,也是一样

使用道具 举报

回复
招聘 : Linux运维
论坛徽章:
7
授权会员
日期:2006-11-25 16:02:41会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB元老
日期:2007-10-15 21:33:22数据库板块每日发贴之星
日期:2007-10-16 01:04:57数据库板块每日发贴之星
日期:2007-10-17 01:03:34ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44优秀写手
日期:2014-06-24 06:00:13
6#
发表于 2007-10-13 16:25 | 只看该作者
Subject:  JDBC Connection Failure: Network Adapter Could not Establish Connection
  Doc ID:  Note:139775.1 Type:  PROBLEM
  Last Revision Date:  28-MAY-2007 Status:  PUBLISHED


PROBLEM
-------

You are attempting to connect to an Oracle instance using JDBC
and you are receiving the following error.

   java.sql.SQLException: Io exception:
     The Network Adapter could not establish connection

   SQLException: SQLState (null) vendor code (17002)

Any or all of the following conditions may also apply:

1) You are able to establish a SQL*Plus connection from the same
   client to the same Oracle instance.

2) You are able to establish a JDBC OCI connection, but not a Thin
   connection from the same client to the same Oracle instance.

3) The same JDBC application is able to connect from a different
   client to the same Oracle instance.

4) The same behavior applies whether the initial JDBC connection
   string specifies a hostname or an IP address.

REDISCOVERY
-----------

To verify whether you are hitting this problem, verify whether the
Oracle instance is configured for Multithreaded Server (MTS).

If the Oracle instance is not configured for MTS, you are probably
encountering a different problem. Otherwise, continue.

Try forcing the JDBC connection to use a dedicated server instead
of a shared server. This can be accomplished in several ways.

For JDBC OCI or Thin, this can be done by reconfiguring the server
for dedicated connections only. This approach, however, may not be
feasible in many cases. In such cases, the following options apply:

For JDBC OCI:

1) Add the (SERVER=DEDICATED) property to the TNS connect string
   stored in the tnsnames.ora file on the client.

2) Set the user_dedicated_server=ON in sqlnet.ora on the client.

For JDBC Thin:

You must specify a full name-value pair connect string (the same
as it might appear in the tnsnames.ora file) instead of the short
JDBC Thin syntax. For example, instead of

   "jdbcracle:thin:@hostort:sid"

you would need to use a string of the form

   "jdbcracle:thin:@(DESCRIPTION="                   +
                         "(ADDRESS_LIST="              +
                             "(ADDRESS=(PROTOCOL=TCP)" +
                                      "(HOST=host)"    +
                                      "(PORT=port)"    +
                             ""                       +
                         ""                           +
                         "(CONNECT_DATA="              +
                             "(SERVICE_NAME=sid)"      +
                             "(SERVER=DEDICATED)"      +
                         ""                           +
                       ""

If the connection works fine after having made these changes, it
is very likely that this is the problem you are encountering. In
this case, one last test will help to verify this fact.

Log into the remote host on which the Oracle instance is running
and execute the appropriate command to determine what the server
'thinks' its hostname is (i.e. the name that was configured when
the server was installed and configured). For example, on a Unix
host the 'hostname' command can be used for this purpose.

Using the name displayed (e.g. by the hostname command), exactly
as it appeared (i.e. if the output from the hostname command had
the domain name included, then include it), return to the client
which was unable to connect and try pinging the server.

NOTE: It is critical that you attempt to ping the server using
      EXACTLY the same hostname you got from the server.

If you are unable to ping the server via this hostname, then you
almost certainly hitting this problem. If not, this may be a new
issue, but at least you will have found a workaround (i.e. use a
dedicated connection).

EXPLANATION
-----------

To understand why this problem occurs, one must first understand
the differences in how the listener handles connections to shared
servers versus dedicated servers.

When connecting to a dedicated server, the client connects to the
listener (via hostname or IP address). The listener then spawns a
dedicated server process and hands off the socket used to accept
the client connection to that server. The client and server then
start communicating via the endpoints established by the initial
connection. NOTE: There is only one connection in this case.

When connecting to a shared server, the initial client connection
to the listener is the same. However, with MTS, there is no need
to spawn a new server process; a pool of shared processes already
exists. Also, clients do not communicate directly with the server
processes in MTS; rather, they communicate with a dispatcher.

For this reason, when setting up an MTS connection, the listener
sends a redirect message back to the client asking the client to
close the connection to the listener and connect to a dispatcher.
The information in this message includes the hostname and a port
number for the appropriate dispatcher. The redirect message will
ALWAYS specify a hostname, even if the client initially provided
an IP address.

If, for any reason, the hostname provided to the listener (e.g. by
the 'hostname' or another command) doesn't agree with the hostname
by which the server is known on the client, the connection fails.

On the other hand, if "(SERVER=DEDICATED)" already appears in the
TNS connect string in tnsnames.ora or if "use_dedicated_server=ON"
already appears in the sqlnet.ora file, you may find that SQL*Plus
and/or JDBC OCI work fine, while JDBC Thin fails.

SOLUTION
--------

Obviously, one solution is to use dedicated servers. However, this
may not always be feasible.

The key is to make sure the hostname on both the client and server
agree. This can be accomplished by reconfiguring either the client
or the server, but there are things to be aware of in both cases.

In a Unix environment, the "host" command can be used  to determine what
IP address a name will be resolved as for example:

$ host mymachine.oracle.com
mymachine.oracle.com   has address 111.222.333.444

In a Unix environment, the "hostname" command can be used to display the
name of the machine as defined by the /etc/host file or by a DNS server,
for example:
  
$ hostname
mymachine.oracle.com

If the IP address of the current host is not known then do /sbin/ifconfig to
display this information ( look for attribute label "inet addr"

If the server is configured to return a different hostname, then it
is possible that other clients which used to work will now fail.

In some cases, it may not be feasible to reconfigure the client. For
example, if the server version of the hostname does not include the
domain, you would need to remove the domain portion of the hostname
on the client; but, if the client needs to connect to more than one
server with the same base name in different domains, this may not be
possible, as the hostname may be ambiguous.  So the solution in Unix
is to  place the name on the /etc/hosts file as an ALIAS.  

The /etc/hosts is made up of a line for each host  in the form
IP_ADDRESS    HOSTNAME    ALIAS

When
        $> lsnrctl stat
is issued.  the entry after HOST= must match IP_ADDRESS HOSTSNAME ALIAS
in the /etc/hosts file.

使用道具 举报

回复
论坛徽章:
1
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44
7#
发表于 2007-10-16 10:28 | 只看该作者
在数据导入,我也遇到了这样的问题。现在数据量大,导入一半时出现,以至于没办法完全导入数据。
找不到原因=。=

直接捕获异常解决。。。。


Connection conn;
try {
     conn = DriverManager.getConnection(url, username, password);
} catch (SQLException ex) {
     conn = DriverManager.getConnection(url, username, password);
}

使用道具 举报

回复
论坛徽章:
9
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:08:29ITPUB9周年纪念徽章
日期:2010-10-08 09:28:522011新春纪念徽章
日期:2011-02-18 11:42:47ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
8#
发表于 2007-10-17 18:03 | 只看该作者
这些淫呐,问题解没解决也不反馈一下,想问的时候哭着喊着的问,解决了就一个屁都不放,也不给后来者点参考,BS之!!!

使用道具 举报

回复
论坛徽章:
0
9#
发表于 2007-11-6 12:30 | 只看该作者
Check your database server's TNS set up.
On your client talking to the db server, you need to be able to ping the
db server using the same hostname as that is in the TNS set up.

For example, the server TNS set up has -
RACDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = RAC1)(PORT = 6015))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RACDB)
      (INSTANCE_NAME = RACDB1)
    )
  )
RACDB2=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = RAC2)(PORT = 6015))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RACDB)
      (INSTANCE_NAME = RACDB2)
   )
)

RACDB=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = RAC1)(PORT = 6015))
    (ADDRESS = (PROTOCOL = TCP)(HOST = RAC2)(PORT = 6015))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RACDB)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
    )
  )
)

Then on your client side, you need to be able to ping RAC1 and RAC2.
If you can't ping and your client is linux or unix, you may get intermittent
connection from your JDBC Java application.

Hope it helps.
Kang

http://www.all-review.com

使用道具 举报

回复
论坛徽章:
1
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44
10#
发表于 2007-11-6 14:51 | 只看该作者
这个问题我也遇到过,数据量突然增加,JDBC连接就会报出这个错误来,我一般的解决是把监听重新做一遍,我怀疑是不是JDBC和监听之间有bug啊。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表