DB2 Quick Tip: Checking Connection State

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

Ember Crooks
Ember Crooks

Ember is always curious and thrives on change. She has built internationally recognized expertise in IBM Db2, spent a year working with high-volume MySQL, and is now learning Snowflake. Ember shares both posts about her core skill sets and her journey learning Snowflake.

Ember lives in Denver and work from home

Articles: 555


  1. Excellent! I don’t know how I had never stumbled across that before. I ususally just type db2 connect, but it’s not good at detecting if you’ve been forced, such as if the db has been quiesced.
    Thanks for the tip 🙂

  2. Is there any property that maintains the DB2 connection status that I can refer to rather than checking the connection status using if x = ‘Open”.
    I am thinking something like this
    If IBM.Data.DB2.DB2Connection::State.Open

  3. this command cannot be used to check instance status.
    it says connectable when database manager is down
    so I’m not sure how it’s useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.