Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adaptive server connection failed (DB-Lib error message 20002, severity 9)

I'm sure this issue has been raised an uncountable number of times before but perhaps, someone could still help me.
I am using pymssql v2.1.3 with Python 2.7.12 and the code that I used several times until yesterday to write data to my Azure SQL DB has somehow decided not to work anymore - for no apparent reason.

The firewall is set, my IP is in the whitelist, I can connect to the database using SQL Server Management Studio and query the data but I still keep getting this error when attempting to connect using pymssql.

The app is a Flask web-app and following is how I connect to the DB:

conn = pymssql.connect(server='myserver.database.windows.net', user='myusername@mydatabase', password='mypassword', database='mydatabase')
like image 558
Syed Avatar asked Dec 23 '22 23:12

Syed


2 Answers

This is likely due to the pymssql version. Did you upgrade pymssql? If yes, try reverting back to 2.1.1

sudo pip install pymssql==2.1.1
like image 197
meet-bhagdev Avatar answered Feb 08 '23 23:02

meet-bhagdev


Not really a solution to the issue I raised, but using pypyodbc instead of pymssql works.

conn = pypyodbc.connect(driver='{SQL Server}',server='tcp:myserver.database.windows.net,1433',database='mydatabase', uid='myusername', pwd='mypassword')
like image 24
Syed Avatar answered Feb 08 '23 22:02

Syed