Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to conect to DB
#1
while using Jupyter NB am connecting to my DB.

code i write is:

try:
conn = ibm_db.connect(dsn, "dashdb-txn-sbox-yp-lon02-04.services.eu-gb.bluemix.net,")
print ("Connected to database: ", dsn_database, "BLUDB: ", dsn_uid, "zxw96000: ", dsn_hostname)

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

Error I get is:

Error:
-------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-32-f542abbf5e0c> in <module> 1 try: ----> 2 conn = (ibm_db).connect(dsn, "dashdb-txn-sbox-yp-lon02-04.services.eu-gb.bluemix.net,") 3 print ("Connected to database: ", dsn_database, "BLUDB: ", dsn_uid, "zxw96000: ", dsn_hostname) NameError: name 'ibm_db' is not defined During handling of the above exception, another exception occurred: NameError Traceback (most recent call last) <ipython-input-32-f542abbf5e0c> in <module> 4 5 except: ----> 6 print ("Unable to connect: ", ibm_db.conn_errormsg()) NameError: name 'ibm_db' is not defined
what am i doing wrong?
Reply
#2
First of all, next time please put your code in a Python codeblock.

I have no experience with Jupyter, but according to the traceback you forgot to define the variable
ibm_db
. In other words, you are using a variable that does not exist.
Reply
#3
As the error message says, 'ibm_db' is not defined. Before you call ibm_db.connect you must first define ibm_db to be something. THis is done through assignment or import.

My guess, from your title, is you are trying to call the connect function from the IBM database package. Do you have an "import ibm_db"?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use quandl to conect TSE ian 1 3,085 Jul-05-2017, 08:44 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020