Trying to connect to an MS SQL server in Python.
import pymssql
server = '172.17.149.7\SQLEXPRESS'
user = 'test_user'
pw = 'test_pw'
db = 'test_db'
conn = pymssql.connect(server=server, user=user, password=pw, database=db)
Funny enough, this worked yesterday. Today, I get an error:
(20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect:
Adaptive Server is unavailable or does not exist (172.17.149.7\\SQLEXPRESS)\n')
Looking into this, I found that the underlying FreeTDS already encounters problems when trying to connect.
tsql -S 172.17.149.7\SQLEXPRESS -U test_user -P test_pw
Error 20012 (severity 2):
Server name not found in configuration files.
locale is "de_DE.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20013 (severity 2):
Unknown host machine name.
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
There was a problem connecting to the server
From what I understand, it cannot find the server name in its configuration file freetds.conf
. This is fine, I did not put it there (doing so does not make a difference) and after looking there it tries to find the server on the network. However, Unknown host machine name.
seems to mean that the server cannot be found on the network. It then proceeds to not be able to connect to the server, since it apparently does not even see it.
It is there, though. Using a GUI (HeidiSQL) to connect to the database works just fine. Also, that very same code above worked just a day ago. I did not knowingly change anything in the meantime, just shutdown and restarted the computer.
What could be going on here?