Search code examples
db2ibm-cloud

Can not connect to IBM_Cloud DB2 database using credentials (as API or Cloud console)


I can not execute SQL queries in IBM cloud or through Python ibm_db API. Connection is refused.

I have registered for IBM cloud services. I was able to start a DB2 instance and created a connection successfully. However when I launch the console (from inside cloud) and try to run SQL queries, the connection is refused. The same refusal happens if I use ibm_db API using Python. To the best of my abilities, I have entered correct details. One thing however I notice that the automatically created connection password does not have a Capital letter and there is always a + sign somewhere. As an aside question, how do I change the password for a connection?

```python
import ibm_db
#Replace the placeholder values with your actual Db2 hostname, username, and password:
dsn_hostname = "somehostname" # e.g.: "dashdb-txn-sbox-yp-dal09-04.services.dal.bluemix.net"
dsn_uid = "abc12345"        # e.g. "abc12345"
dsn_pwd = "6fabcde57+ghijkl8"      # e.g. "7dBZ3wWt9XN6$o0J"

dsn_driver = "{IBM DB2 ODBC DRIVER}"
dsn_database = "BLUDB"            # e.g. "BLUDB"
dsn_port = "50000"                # e.g. "50000" 
dsn_protocol = "TCPIP"            # i.e. "TCPIP"

dsn = (
    "DRIVER={0};"
    "DATABASE={1};"
    "HOSTNAME={2};"
    "PORT={3};"
    "PROTOCOL={4};"
    "UID={5};"
    "PWD={6};").format(dsn_driver, dsn_database, dsn_hostname, dsn_port, dsn_protocol, dsn_uid, dsn_pwd)


try:
    conn = ibm_db.connect(dsn, "", "")
    print ("Connected to database: ", dsn_database, "as user: ", dsn_uid, "on host: ", dsn_hostname)

except:
    print ("Unable to connect: ", ibm_db.conn_errormsg() )
```

[IBM][CLI Driver] SQL30082N Security processing failed with reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001 SQLCODE=-30082

Similar error happens when I am trying to run SQL queries through DB2 cloud console.

Image describing the error from the IBM cloud DB2 SQL console

Thank you for your time


Solution

  • I figured it out by chance. Every time when I was starting the Db2 database it said that it might take some time to provision. I overlooked it as immediately it printed "provisioned". At that time I used to go straight to create a connection and start using SQL queries. It did not work.

    However last time (when it worked) I created a Db2 instance and then could not log in to IBM Cloud for a day or two. Next time when I logged in, it was accepting SQL queries flawlessly! I went ahead and created a connection so that I could work through local Jupyter notebooks and that worked too.

    So I guess in this case the solution was to just wait, rather than keep creating and deleting Db2 instances in the hope that it will start working. IBM staff can better comment if this was indeed the case but for the time being I am happy. Hope this helps to somebody in future.