Windows – How to find DB2 port number (note: it does not use port listed in services file and db2 listing is missing from netstat command output) in windows

db2javaportwindows

I want to find DB2 port in windows, please help. Some information:

  1. DB2 v 9.7 Personal Edition – new/fresh install
  2. netstat command does not list db2 port.
  3. db2 entry missing was missing in system32\drivers\etc\services file so, made an entry – "db2c_DB2 50000/tcp"
  4. able to start db2 using control center and create tables and insert rows
  5. able to start db2 using CLP and perform opertaions

Actually, I'm trying to connect to DB2 using "jdbc:db2://127.0.0.1:50000/TEST" as connect URL from Java but, I get an error:
"Exception java.net.ConnectException: Error opening socket to server /127.0.0.1 on port 50,000 with message: Connection ref
used: connect. ERRORCODE=-4499, SQLSTATE=08001"

I find that DB is up and running but, not listening on port 50000, though mentioned in services file. So, db2 is listening on some other port but,

  1. what's the port it's using?
  2. why it's not using port #50000 as mentioned in services file?
  3. why netstat command is not listing db2 service and port information?

Thanks much in advance.

Best Answer

Firstly make sure TCP comms is set on,

db2cmd -i -w
db2set DB2COMM=npipe,tcpip
db2stop
db2start

You can check if it's not using the default port,

db2cmd -i -w
db2 get dbm cfg | find "SVCENAME"

Should get a line like this,

TCP/IP Service name                          (SVCENAME) = db2c_DB2

The above would should a port number if it was not set to default port, as you can see my config is default (=50000)