Blog Post

Azure Database Support Blog
2 MIN READ

Lesson Learned #269: Unable to connect - Is unavailable or does not exist - Connection Time out

Jose_Manuel_Jurado's avatar
Jan 08, 2023

Today, I worked on a service request that your customer is facing the following error message: During handling of the above exception, another exception occurred: Traceback (most recent call last): File "src/pymssql/_pymssql.pyx", line 653, in pymssql._pymssql.connect pymssql._pymssql.OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (servername.database.windows.net)\nNet-Lib error during Connection timed out (110)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (servername.database.windows.net)\nNet-Lib error during Connection timed out (110)\n')

 

It is a python application using pymssql library running in Ubuntu 18.04. Our customer reported that previous connections were fine  and this issue suddenly happened. 

 

After checking the port 1433 and redirection ports in Network Security Groups we didn't see any issue.

 

To check if the ports are available from this machine we ran the command telnet servername.database.windows.net 1433 and we saw  that is not possible to connect.

 

The IP reported is 10.10.1.25. This IP looks like a private link but checking the private link the IP has dynamically changed to 10.10.1.26. In this situation, we checked the DNS server and Local DNS for Private Link and everything is fine, so the next action was to review if we have any configuration in the hosts file of Linux. We found that they have this configuration in their file. 

 

Changing the value of /etc/host file from 10.10.1.25 to 10.10.1.26 everything was started to work correctly and we suggested to discuss with their IT Security team to check why this situation happened or change the private link to static. 

 

 

Enjoy!

 

Updated Jan 08, 2023
Version 2.0
  • Basav_Raj's avatar
    Basav_Raj
    Copper Contributor

    Getting Same error while trying to connect Sql Server Database MS Community Could you please take a look I have shared  code snap and exception:
    My Code:

    import pymssql

    def readdata_pymssql():
    print('conn details of pymssql')
    connectionString = f'SERVER={SERVER};DATABASE={DATABASE};UID={USERNAME};PWD={PASSWORD}'
    #conn = pymssql.connect(connectionString,as_dict=True)
    print(pymssql)
    conn = pymssql.connect(server='.\SQLEXPRESS',user='sa',password=PASSWORD,database=DATABASE, as_dict=True)
    print('Connected..')
    SQL_QUERY = """
    SELECT
    * from books;
    """
    cursor = conn.cursor()
    cursor.execute(SQL_QUERY)

    records = cursor.fetchall()
    print(records)


    DB_Conn.readdata_pymssql()



    Exception:


    Traceback (most recent call last):
    File "C:\RND\pythonRND\DB_Conn.py", line 44, in <module>
    DB_Conn.readdata_pymssql()
    File "C:\RND\pythonRND\DB_Conn.py", line 30, in readdata_pymssql
    conn = pymssql.connect(server='.\SQLEXPRESS',user='sa',password=PASSWORD,database=DATABASE, as_dict=True)
    File "src\\pymssql\\_pymssql.pyx", line 653, in pymssql._pymssql.connect
    pymssql._pymssql.OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost)\n')

  • Hello Basav_Raj , the source code doesn't seem the problem here, all points that the sqlExpress in your desktop is not running or is not listening the neccesary ports. Please, try to use with SQL Server Management Studio and review if your are able to connect to SQLExpress. Check the connection string.