I have created a Fast API application for my job. This is hosted on a windows server. It’s wrapped as a windows service using pyWin32 and runs a FastAPI app using Uvicorn. This works. We have a snippet of code to connect to our MS server SQL DB, we do this using the Pyodbc library.
The connection works, establishing a tcp conneciton to the server every time but occasionally the query times out and no data is transferred. This seems to happen randomly after a period of time or when a large volume of rest calls happen quickly. I’ve tried increasing the time out parameter and done error handling so no tcp connections stay open. Does anyone have any advice.
The connection code is very straight forward, we use windows authentication and specify the driver, server, database, timeout and trusted connections parameters. We then create the cursor, execute the query, commit it then close everything in a Finally statement.
Specific error message: errors inserting records into DB 08001 the wait operation timed out, Login timeout expired (0). A network-specific or instance-specific error has occured while establishing a connection to SQL Server. Server is not found or not accessible…
Tried increasing the timeout.
Tried implementing better error handling and enforcing connections are closed.
Lucas Williamson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.