Nigel Verlé
Nigel Verlé

Reputation: 1

Connect to local SQL server

I run the following code in Python on mac M1:

import pyodbc
server = 'localhost' 
username = 'sa' 
password = 'password' 
database = 'Fin_Data_TST' 
db_connection_string = "Driver={ODBC Driver 18 for SQL Server};Server=" + server + ";Database=" + database + ";UID=" + username + ";PWD=" + password + ";"
conn = pyodbc.connect(db_connection_string, autocommit=True)

I receive an error:

pyodbc.OperationalError: (‘HYT00’, ‘[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0) (SQLDriverConnect)’)

I run a SQL server in docker on the same mac device with image = Microsoft Artifact Registry

How can I debug this error? It seems that I don’t receive a connection request when I check the SQL logs. I ran

drivers = pyodbc.drivers()
for d in drivers:
    print(d)

To check if I have the correct drivers. I also tried different names for server variable, adding the IP address, port, changing ODBC driver to 17, … I can connect to the database with the same credentials via Azure Data Studio.

Upvotes: 0

Views: 99

Answers (0)

Related Questions