您的位置:首页 > 数据库

一次DB2数据库连接失败(SQLSTATE=08001)的解决方法

2016-06-22 09:08 513 查看
有一次,在使用DbVisualizer工具连接自己linux虚拟机上的DB2数据库时,报如下错误:

Product:  DbVisualizer Pro 9.1
Build:  #2050 (2013/09/08 11:03)
Java VM:  Java HotSpot(TM) 64-Bit Server VM
Java Version:  1.6.0_43
Java Vendor:  Sun Microsystems Inc.
OS Name:  Windows 7
OS Arch:  amd64
OS Version:  6.1

An error occurred while establishing the connection:

Long Message:
[jcc][t4][2043][11550][4.15.82] 异常 java.net.ConnectException:打开端口 50,000 上服务器 /192.168.17.88 的套接字时出错,消息为:Connection timed out: connect。 ERRORCODE=-4499, SQLSTATE=08001

Details:
Type: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException
Error Code: -4499
SQL State: 08001


在百度上搜索"DB2 SQLSTATE=08001",找到如下资料:

这种问题一般的原因:
1.DB2COMM=TCPIP
2.数据库故障
3.端口号被禁用

解决方案:

1.看看端口号有没有配置正确,看一下配置参数svcename跟services文件中配置的db2端口号是否一致,windows一般用50000,unix/linux一般用60000。
2.连接出错首先看看服务器ip 和端口写对没有。
ip如果没错就要看看服务器的db2服务端口对不对。另外对于服务器下面这些也要注意。

检查服务器的配置情况如下:

验证存在的DB2数据库
db2 list db directory
db2 list db directory show detail
验证实例使用的通讯协议,查看DB2COMM变量
db2set -all
查看数据库管理器的配置,查看SVCENAME(特指tcpip协议)
db2 get dbm cfg
查看/etc/services中,有无与上面对应SVCENAME的端口,例如:
db2cDB2 50000/tcp

要确认服务器是否在监听,可以用netstat -an 来查看端口是否处于LISTEN状态。


查看我linux虚拟机上的db2数据库端口设置:

[root@localhost ~]# cat /etc/services | grep db2c_db2inst1
db2c_db2inst1 50000/tcp


端口设置没有问题,在看防火墙设置:

[root@localhost ~]# service iptables status
±í¸ñ£ºfilter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:81
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8080
8    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8081
9    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8001
10   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8002
11   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@localhost ~]#


原来防火墙没有开启50000端口。编辑该文件,在里面添加一条记录:

11 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:50000

添加完之后,重启iptables设置(一定要重启,否则不生效),并再次查看防火墙端口设置信息(注意红色标记部分):

[root@localhost ~]# service iptables restart
清除防火墙规则:                                           [确定]
把 chains 设置为 ACCEPT 策略: filter                      [确定]
正在卸载 Iiptables 模块                                    [确定]
应用 iptables 防火墙规则                                   [确定]
[root@localhost ~]# service iptables status
±í¸ñ£ºfilter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:81
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8080
8    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8081
9    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8001
10   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8002
11   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:50000 
12   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@localhost ~]#


再次使用DbVisualizer工具连接数据库,成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: