can't connect to Azure SQL using SQLAlchemy with pymssql - python

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

Related

Error connecting DB2 instance on IBM cloud

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?

(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

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

Unable to connect using pymssql with windows authentication

While trying to connect to MSSQL Server 2012 using pymssql, I get the following error.
My server name in Windows Authentication is SARATH,User Name is Sarath\SarathShanker and I did not set a password.
Code:
mssql_conn=pymssql.connect(host='SARATH',user='Sarath\SarathShanker',password='',database='matrix')
Error:
Traceback (most recent call last):
File "", line 1, in
File "pymssql.pyx", line 556, in pymssql.connect (pymssql.c:7990)
pymssql.OperationalError: (18452, 'Login failed. The login is from an untrusted
domain and cannot be used with Windows authentication.DB-Lib error message 18452
, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB
-Lib error message 20002, severity 9:\nAdaptive Server connection failed\nDB-Lib
error message 18452, severity 14:\nGeneral SQL Server error: Check messages fro
m the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server conne
ction failed\n')
How should I modify my script in order to connect to MSSQL Server using pymssql.
P.S I have already imported pymssql as well. (Not Shown in Code above)
Try this:
conn = pymssql.connect(host='myhost', database='mydb')
This is with Python Version 3.4 and for Windows Authentication.
If on RHEL, try
os.environ["FREETDSCONF"] = "/etc/freetds.conf"
If you are using the latest version of pymssql (I use 2.1.3),
pymssql.connect(server='<TEST_SERVER>', database='<TEST_DB>')
Simply replace the '' and '' with your server and DB name.

Categories