Getting error while deploying an python-app into k8s that connects to serverless sql: pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

Suraj Shashidhar 65 Reputation points
2025-02-26T20:14:25.0166667+00:00

Hello,

We are trying to deploy a python app into k8s that can connect to synapse serverless sql.

I can connect to synapse serverless sql through the same app running from my local machine.

But it fails with 'Login Connection Timeout' error. We added the k8s ips to synapse networking whitelist table, but it still fails. The nslookup/netcat resolves to database correctly from inside k8s

Are there any config changes required to enable access to synapse serverless sql pool from python?

conn_str = (
    "DRIVER={ODBC Driver 18 for SQL Server};"
    "SERVER=our-serverless-ondemand.sql.azuresynapse.net;"
    "DATABASE=SampleDB;"
    "Authentication=ActiveDirectoryPassword"  # Use the correct authentication method
    "UID=******@company.com;"
    "PWD=ComplexPassword-1234;"
    "TrustServerCertificate=yes;"
    "Connection Timeout=60;"
    "Trace=Yes;"
"TraceFile=/app/odbc_trace.log;"
)

conn = pyodbc.connect(conn_str)
# we get:  pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,378 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ganesh Gurram 7,295 Reputation points Microsoft External Staff Moderator
    2025-02-26T22:51:00.12+00:00

    Hi @Suraj Shashidhar

    Thank you for posting your query!

    The login timeout error usually indicates that your Kubernetes pod cannot establish a connection to the Synapse Serverless SQL pool. Since your local machine works but Kubernetes fails, the issue is likely related to network configuration or authentication.

    Network Configuration - Ensure that your Synapse serverless SQL pool's firewall settings allow connections from the IP addresses of your Kubernetes nodes. Double-check that these IPs are added correctly. Ensure your Kubernetes cluster can initiate outbound connections to the internet, as Azure Synapse is a cloud service.

    DNS Resolution - Although you've mentioned that nslookup resolves correctly, ensure that there are no intermittent DNS issues.

    Authentication Issues - Ensure that the authentication method (ActiveDirectoryPassword) is correctly configured and supported. Double-check the username and password. If you're using Azure Active Directory (AAD) for authentication, make sure that the Kubernetes environment has access to the necessary AAD endpoints and that the credentials have the correct permissions.

    ODBC Driver and TLS - Ensure that you're using the correct version of the ODBC driver that supports Azure Synapse. Although you have TrustServerCertificate=yes, ensure there are no SSL/TLS handshake issues. You might need to configure the certificate settings more explicitly.

    Kubernetes Environment - Network Policies: If you're using network policies within your Kubernetes cluster, ensure that the pods running your application have the necessary permissions to initiate outbound connections. Ensure there are no security policies that might block the connection.

    Similar issues: https://techcommunity.microsoft.com/blog/azuredbsupport/lesson-learned-258-python-vs-connection-refused-with-login-timeout-expired/3703542

    https://stackoverflow.com/questions/77652025/how-can-you-connect-to-serverless-sql-pool-using-notebooks

    https://community.fabric.microsoft.com/t5/Data-Engineering/Pyodbc-Connect-to-Warehouse-Endpoint-timing-out/m-p/4288601#M5238

    https://stackoverflow.com/questions/54069846/pyodbc-operationalerror-hyt00-uhyt00-unixodbcmicrosoftodbc-driver-1

    Reference: https://learn.microsoft.com/en-us/azure/azure-sql/database/connectivity-architecture?view=azuresql

    I hope this information helps.

    Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues. 

    0 comments No comments

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.