0

I'm trying to connect to an IBM DB2 database using SQLAlchemy connection format but it keeps failing to connect.

I am using these libraries:

!pip install sqlalchemy==1.3.9
!pip install ibm_db_sa
!pip install --force-reinstall ibm_db_sa ibm_db

Loading the connector:

%load_ext sql

My connection string:

%sql ibm_db_sa://jqg6xxxx:r9C98t4TY81xxxxx@fbd88901-ebdb-4a4f-a32e-9822b9fb237b.c1ogj3sdxxxxxtu0lqde00.databases.appdomain.cloud:32731/bludb?security=SSL

Error message:

Connection info needed in SQLAlchemy format, example:
           postgresql://username:password@hostname/dbname
           or an existing connection: dict_keys([])
'sqlalchemy.cimmutabledict.immutabledict' object does not support item deletion
Connection info needed in SQLAlchemy format, example:
           postgresql://username:password@hostname/dbname
           or an existing connection: dict_keys([])

I am actually using this format but it just won't work.

2
  • 1
    The README seems to suggest that your connection URL string should start with db2+ibm_db:// Commented Nov 6, 2021 at 20:57
  • You could also try using URL.create() like this Commented Nov 6, 2021 at 21:32

2 Answers 2

3

Your connection string seems malformed: instead of ending with /bludb?security=SSL as shown in your question, try instead using the ending below:

/bludb;security=SSL;

Notice the sem-colon prefix and suffix.

Works for me with SQLAlchemy 1.3.24 and ibm_db 3.1.0 and ibm_db_sa 0.3.7. Requires that all other parts of the connection string are correct of course.

Also: both the prefix ibm_db_sa://.... and db2+ibm_db:// work for me to Db2 on Cloud (lite).

Sign up to request clarification or add additional context in comments.

1 Comment

Have you used db2 in flask for SQLALCHEMY_DATABASE_URI ?
0

The error stated the format is username:password@hostname/dbname. You will see in yours that you added the port number So the the the change will be jqg6xxxx:r9C98t4TY81xxxxx@fbd88901-ebdb-4a4f-a32e-9822b9fb237b.c1ogj3sdxxxxxtu0lqde00.databases.appdomain.cloud/bludb?security=SSL I had the same issue recently and it worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.