Error connecting DB2 instance on IBM cloud - python

I am trying to connect to DB2 instance on IBM Cloud using the below code:
%sql ibm_db_sa://nlf36689:25s9wzjqm%40mtbz8z#dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB
I am getting a error as:
(ibm_db_dbi.OperationalError) ibm_db_dbi::OperationalError: Exception('[IBM][CLI Driver] SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "169.44.98.106". Communication function detecting the error: "connect". Protocol specific error code(s): "10060", "", "". SQLSTATE=08001\r SQLCODE=-30081')
(Background on this error at: http://sqlalche.me/e/e3q8)
Connection info needed in SQLAlchemy format, example:
postgresql://username:password#hostname/dbname
or an existing connection: dict_keys([])
Can anyone please help me out?

Related

(pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query)

I am having problem querying to a MariaDB database that is hosted on a Virtual Machine. I am using the dataset Python module.
This is my code:
import dataset
db = dataset.connect("mysql+pymysql://....")
Q = "select * from mytable Limit 1"
print(db.query(Q))
However I would get this error message:
(pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server
during query ([WinError 10060] A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to
respond)') (Background on this error at: http://sqlalche.me/e/e3q8)
I have tried to configure the timeout variables such as; connect_timeout, wait_timeout etc within the my.cnf file and sending a very simple query, but the issue still exist.
Any solutions or suggestions would be highly appreciated. Thank you

Cannot Connect Using SQL Alchemy Unknown MySQL server host

I am trying to connect to a MySQL database on my local machine. I am able to connect using MySQL Workbench, but when I try to use sqlalchemy it does not allow me to connect.
The user has the correct permissions. I can connect using MySQL bench so I know the credentials are correct.
engine = create_engine('mysql://username:password!# ***.***.***.**:3306/ceesmart')
connection = engine.connect()
OperationalError: (_mysql_exceptions.OperationalError) (2006, "Unknown MySQL server host ' ..*.' (2)") (Background on this error at: http://sqlalche.me/e/e3q8)
I don't know if it was on copying and pasting here, but you have an "space" between the # and the first octect:
# ***.*
^ here
That could make the engine to try to resolve it as a DNS name instead of an IP address, therefore, raising Unknown Host exception

can't connect to Azure SQL using SQLAlchemy with pymssql

Using SQLAlchemy to connect to SQL Server on Azure.
I can access it via JDBC using SQL Workbench/J from same IP.(opened the IP in Azure)
Using the string:
mssql+pymssql://username:password#SQLservername.database.windows.net
Getting:
(pymssql.OperationalError) (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (nibisql1.database.windows.net:1433)\n') (Background on this error at: http://sqlalche.me/e/e3q8)
I tried all variations, but none of them work.
any idea why?
How do I pass parameters such as databasename?
Try to change
mssql+pymssql://username#SQLservername:password#SQLservername.database.windows.net

Database connection failed for local MSSQL server with pymssql

I had been working with pyodbcfor database connection in windows envirnment and it is working fine but now I want to switch to pymssql so that it is easier to be deployed to Linux machine as well. But I am getting this error:
(20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost:1433)\nNet-Lib error during Unknown error (10060)\n')
My connection code for using both pyodbc and pymssql is:
import pyodbc
import pymssql
def connectODSDB_1():
conn_str = (
r"Driver={SQL Server};"
r"Server=(local);"
r"Database=populatedSandbox;"
r"Trusted_Connection=yes;"
)
return pyodbc.connect(conn_str)
def connectODSDB_2():
server = '(local)'
database = 'populatedSandbox'
conn = pymssql.connect(server=server, database=database)
return conn
What could be the problem? And solution?
Well after browsing internet for a while, it seems pymssql needs TCP/IP be enabled for communication.
Open Sql Server Configuration Manager
Expand SQL Server Network Configuration
Click on Protocols for instance_name
Enable TCP/IP
I have faced the same issue while using RDS(AWS database instance). We should configured the inbound outbound rules.
Do following steps to configure.
Services->RDS->DB Instances -> Select DB-> Connectivity&Security
Under Security Section
VPC security groups -> click on security group
Change the inbound rules.
Check the source IP and change into anywhere or specific IP

Cannot connect to SQL\Express with pyodbc/pymssql and Robot Framework

I'm having issues connecting to a working SQL\Express database instance using Robot Framework's DatabaseLibrary.
If I use either Connect To Database with previously defined variables or Connect To Database Using Custom Params with a connection string, I get the following results:
pyodbc: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)')
pymssql:: InterfaceError: Connection to the database failed for an unknown reason.
The connection string I'm using is the following: 'DRIVER={SQL Server};SERVER=localhost\SQLExpress;UID=sa;PWD=mypass;DATABASE=MyDb'
I copied several examples from guides and tutorials and all of them yield the same result, so my guess is that there is something wrong on my end, but I just can't figure out what. I can access the database using the Microsoft SQL Server Management Studio just fine, so the database is running.
Any guidance will be greatly appreciated!
I was able to connect using #Goralight approach: Connect To Database Using Custom Params pymssql ${DBConnect} where ${DBConnect} contained database, user, Password, host and port

Categories