Sometimes the connection state is unclear. The following can all make it fuzzy wether or not you have a valid connection:
- A db2 error or warning related to your connection
- A system error related to network connectivity
- Changing VPNs or adding a VPN connection
- Leaving a connection up overnight or over longer periods
This tip is strictly related to the DB2 command line. Various database interfaces in scripting languages or tools may have another way of doing this.
To check a connection state at the DB2 command line, you can issue:
>db2 get connection state Database Connection State Connection state = Connectable and Connected Connection mode = SHARE Local database alias = SAMPLE Database name = SAMPLE Hostname = Service name =
There is no specific authorization needed to execute this command, unlike many DB2 commands.
The possible states include:
- Connectable and connected – meaning you are connected to the database listed
- Connectable and unconnected – you are not connected, but may connect
- Unconnectable and connected
- Implicitly connectable
In addition to the mode of
SHARE seen above, the connection mode could also be
EXCLUSIVE. The Hostname and the Service Name are only populated if the connection is a remote one over TCP/IP.
The Knowledge Center page on the
GET CONNECTION STATE command is: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0001953.html?cp=SSEPGG_10.5.0/3-5-2-4-41&lang=en