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

Tú Nguyễn 170 Reputation points
2024-07-05T06:27:34.9366667+00:00

Hi,

I am encountering an issue while trying to connect to an SQL database using a Python script in my Jupyter notebook. The connection attempt results in the following error message: OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)').

Here is a snippet of the Python code I am using:

from azureml.core import Datastore

from azureml.core import Workspace

import pyodbc

datastore = Datastore.get(Workspace.from_config(), datastore_name='sql_datastore')

SERVER= datastore.server_name

DATABASE = datastore.database_name

USERNAME = datastore.username

PASSWORD = datastore.password

connectionString = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={SERVER};DATABASE={DATABASE};UID={USERNAME};PWD={PASSWORD}'

print(datastore.password)

print(datastore.server_name)

print(datastore.database_name)

print(datastore.username)

with pyodbc.connect(connectionString) as conn:

    cursor = conn.cursor()

    cursor.execute(f"INSERT INTO 'dbo.SampleData' ('Name', 'Age') VALUES ('TuNT', '26')")

    conn.commit()  
```I have verified that the server, database, username, and password are correct. However, I am still unable to establish a connection.  
  
Anyone know how to resolve this error  
  
Many thanks!

SQL Server on Azure Virtual Machines
Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,785 questions
{count} votes

Accepted answer
  1. NIKHILA NETHIKUNTA 2,395 Reputation points Microsoft Vendor
    2024-09-25T04:16:32.89+00:00

    @Tú Nguyễn
    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Ask: Facing an issue while trying to connect to an SQL database using a Python script. Error:
    OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)').

    Solution: The details regarding the server were incorrect. The issue got resolved after correcting the datastore.server_name.

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.


    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.


0 additional answers

Sort by: Most helpful

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.