I am trying to connect to a SQL server that I have on Windows from WSL2 but I am getting a connection timeout error
I am using this piece of code:
import pyodbc
server = 'DESKTOP-LFOSSEF'
database = 'sportsanalytics'
username = 'user'
password = '{pass}'
driver= '{ODBC Driver 17 for SQL Server}'
with pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT TOP 3 name, collation_name FROM sys.databases")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
I get the following error:
Traceback (most recent call last): File "", line 1, in pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Any idea If I need any extra configuration to connect to SQL Server installed on Windows?
Regards