0

I was able to connect to SQL server previously, but now I am no longer able to connect.

The error is:

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

My connection code:

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=DESKTOP-312E8EK;'
                      'Database=Stocks;'
                      'Trusted_Connection=yes;')
Dale K
  • 25,246
  • 15
  • 42
  • 71
Empyz
  • 59
  • 2
  • 11
  • Have you checked all the usual things connection time out debugging methods? You don't actually tell us what you have tried to fix the problem. Have you tried/checked anything? – Thom A Mar 19 '22 at 20:42
  • 2
    `'Server=DESKTOP;'` This seems suspicious - and is inconsistent with your previous questions. – SMor Mar 19 '22 at 20:49
  • I'm not really sure what to do to fix it @larnu I tried repairing sql server files, but I don't really know what to check, since the connection string doesn't seem to need editing and it was working fine for the past few days – Empyz Mar 19 '22 at 21:10
  • @SMor server=desktop is because that's from my other computer but the server name when I do select @@servername in ssms, shows DESKTOP for this one – Empyz Mar 19 '22 at 21:11
  • Considering it's different to your last question, as @Smor noted, it would make sense to check the connection string. – Thom A Mar 19 '22 at 21:11
  • can you give suggestions on what to change/check because I am running a script that has been working for the past few days and suddenly getting a connection error makes no sense as the connection string hasn't changed. could it be an error with pyodbc? – Empyz Mar 19 '22 at 22:10
  • 1
    Your "other" questions use "localhost" as the server name - which is a special value that maps to the machine your app is running on. I suggest you try that. It is odd that you have two different sql server instances installed - one on each machine - which both contain a database named Stocks. Are you certain that is correct? – SMor Mar 19 '22 at 22:12
  • thanks for the reply @SMor - my other questions I just replaced the server name with localhost because I wasn't sure if that is "sensitive" information or not. When I run my actual scripts, the server name that shows up in select @@ servername is what I used to run them and they worked fine. I just opened up the same scripts that have not had any changes to them, and am trying to run them again, but the login timeout expired error just keeps showing up. Other than connection string, what else can I check for troubleshooting? – Empyz Mar 19 '22 at 22:16
  • 1
    If something that was working previously suddenly stops working you need to identify what's changed about the situation. Has Windows Updates just executed updates and "helped things" by disabling required features or updating things in a broken way? Have you moved the script between computers? If "localhost" was working previously but the workstation name isn't working I'd suggest looking at: 1) is the SQL Server instance listening on an accessible IP address (SQL Server Express edition, for example, only listens on 127.0.0.1 by default)? 2) does Windows Firewall allow incoming connections? – AlwaysLearning Mar 19 '22 at 23:28
  • 1
    Check Services.msc to see if SQL Server service stopped running. Start it if you can. BTW - `{SQL Server}` is an old ODBC Driver. Consider changing to the recommended: `{ODBC Driver XX for SQL Server}`. See [Differences Between Drivers for ODBC Drivers](https://stackoverflow.com/q/39440008/1422451). – Parfait Mar 19 '22 at 23:48
  • Possibly related: https://stackoverflow.com/a/52262859/2144390 – Gord Thompson Mar 20 '22 at 12:17

0 Answers0