Home > Mobile >  (pyodbc.OperationalError) ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for
(pyodbc.OperationalError) ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for

Time:08-30

I had a code which used pyodbc to connect with my sql server and it worked fine. Recently I upgraded to WSL2 for some work. Now when I try to run my code it gives me error " (pyodbc.OperationalError) ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired".

What all things I did:

  • Checked for Username and Password.
  • Checked if it worked in SSMS.
  • Checked if I have mentioned the correct port as mentioned over here : https://stackoverflow.com/a/34638867/19231561
  • tried reinstalling sql on my ubuntu
  • Checked if my TCP-IP is enabled.

It still didn't work. I could find a fellow mate facing the same issue but he didn't receive any answer : Remote connection to MS SQL - Error using pyodbc vs success using SQL Server Management Studio

Please suggest me what to do next. Thanks in advance.

Here's my code:

server = "DESKTOP-KI465GS"
database = "db"
username = "user"
password = "pwd"
port = "1433"

params = urllib.parse.quote_plus(
    "driver={ODBC Driver 17 for SQL Server};server="
      server
      ","
      port
      ";database="
      database
      ";Uid="
      username
      ";Pwd="
      password
      ";Encrypt=yes;TrustServerCertificate=yes;Connection Timeout=30;"
)


SQLALCHEMY_DATABASE_URI = "mssql pyodbc:///?odbc_connect=%s" % params
engine2 = create_engine(f"mssql pyodbc:///?odbc_connect={params}", fast_executemany=True)

CodePudding user response:

You are using named pipes.

Try substitute the server name with its IP address and see if it works.

If it works go to sql server configuration manager and enable "Named Pipes" under "Protocols". Then you can use the server name instead of the ip address.

CodePudding user response:

I found this solution which worked for me:

https://stackoverflow.com/a/72842556/19231561

Hope it helps others

  • Related