How to fix timeout error in connection using pyodbc in airflow

Xavier Langa 0 Reputation points
2024-11-23T06:00:19.38+00:00

Hi,

I am running an airflow DAG in docker, where I connect to sql server 2019 using a pyodbc connection function.

My connection function is as:

def get_db_connection():
    return pyodbc.connect(
        'DRIVER={ODBC Driver 17 for SQL Server};'
        'SERVER=xxx.xxx.x.xx\\XXX2024;'
        'DATABASE=somedatabase;'
        'UID=username;'
        'PWD=password;'
    )

When the connection exceeds 15 seconds, I get this error:

return pyodbc.connect( pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

even when setting:

connection.timeout = 30

Can someone help me?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,069 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.